You can learn Python articles without reading online classes (the third day)

Why_ does_ it_ work 2021-11-25 15:31:52
learn python articles reading online

Next to the previous one You don't have to watch online classes to learn python The article ( the second day )_Why_does_it_work The blog of -CSDN Blog

When it comes to statements , Then we should know something python

python The most distinctive feature is the use of indentation to represent code blocks , You don't need braces  {} ;

Lines and indents

if True:

Yes c The basis of language, let's look at this string of code ,python There is no harmony. c Languages also have semicolons and braces. In fact, we can see from the last article , that python How to distinguish ------ Indent

  • The number of indented spaces is variable , But the statements of the same code block must contain the same number of indented spaces ;

  • Generally, four spaces are used to indent the beginning of the line ;

  • Tabs are not recommended tab key , Because different text editors are inconsistent , If you want to run across platforms , Not recommended ;

  • python End of sentence , There is no need to add at the end A semicolon ; 

So here comes the question , What if the two lines are the same sentence , Is in the python Standard formats are generally used in languages to distinguish content so that code can be understood , Then you have to write a string of code on the same line , If you can't write it down, use the symbol \

# "\" example
test = test_one + \
test_two + \

contrary , If you want to write multiple strings of code on the same line, how to distinguish ? use ;

a=1; b="hello world"; c="Why_does_it_work"

Understand the basic sentences clearly , that

Judgement sentence

1.if Conditional sentence

if The conditions to judge :
If it is correct, the operation to be performed

It should be noted that c Language has a basic fixed format ,python There are no complicated symbols, but use indentation ,if In the statement, when the conditions to be judged are written and the line breaks are written, pay attention to , To click tab Button or four spaces ​

It should be noted that the judgment sentence and the indented part are a whole , Step by step from top to next

2.if-else The format of

if The conditions to judge :
Correct operation
Wrong operation

 3.elif sentence

if Conditions 1:
Meet the conditions 1 The operation made
elif Condition 2 :
Meet the conditions 2 Make a statement
elif Condition 3 :
Meet the conditions 3 Make a statement
Not meeting the conditions 123 Executed statements 

This is not in order , At the same time

4.if nesting

if Nesting and elif Totally different ,elif There are indentations in the. They are done at the same time , however if Have priority

if Nesting is and c The language is the same , Judge one by one

Loop statement

stay python There are three kinds of statements in language , Sequential statements , Branch statement , Loop statement

In fact, the statements that operate step by step at the beginning of the article are called sequential statements , stay if-else,elif It's a branch statement

The loop statement is also relatively simple

while loop

abc = 1
while abc<9:
abc+= 1

for loop

for i in range(1,101):
print(i , end = " ")

for Variable in range(10):
The code that the loop needs to execute

range Usage of :
range(stop): 0~stop-1
range(start,stop): start~stop-1
range(start,stop,step): start~stop step( step )

[0, 1, 2, 3, 4]
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(1,11)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> range(1,11,2)        ## Take out the odd number
[1, 3, 5, 7, 9]
>>> range(0,11,2)        ## Take out even numbers
[0, 2, 4, 6, 8, 10]

break sentence ,continue sentence ,pass sentence , We'll talk about it later

I've devoted an issue to circulation , Actually, I know the structure , know python Indentation , and c Language is basically similar

About c Language cycle , What I want to say is :_Why_does_it_work The blog of -CSDN Blog

In the next article, I will train on some topics about sentences and share them with you , I hope you will continue to pay attention !

本文为[Why_ does_ it_ work]所创,转载请带上原文链接,感谢

  1. Python爬虫编程思想(85):在Python中使用非关系型数据库
  2. Volume de réglage audio Python (avec Code) | outils Python
  3. Python crawler programming idea (59): get attribute value and text with beautiful soup CSS selector
  4. Python crawler programming idea (57): basic usage of CSS selector in beautiful soup
  5. Python crawler programming idea (55): find of beautiful soup method selector_ All method
  6. Python crawler programming idea (54): use beautiful soup to select sibling nodes
  7. Python crawler programming idea (53): use beautiful soup to select the parent node
  8. Django3.0 solves the problem of error reporting in reverse parsing
  9. Precautions for Python crawler
  10. Python 3 crawler series (1) -- climbing blind date websites
  11. Python到底是什么?为什么要学Python?
  12. #yyds干货盘点#Pandas数据清洗实用指南
  13. Python打包exe文件无法运行
  14. Two common ways to save files in Python
  15. #yyds幹貨盤點#Pandas數據清洗實用指南
  16. Yyds Dry Inventory pandas Data Cleaning Practical Guide
  17. PYTHON用LSTM长短期记忆神经网络的参数优化方法预测时间序列洗发水销售数据
  18. Python集成学习:自己编写构建AdaBoost分类模型可视化决策边界及sklearn包调用比较
  19. Python 3 makes a search software
  20. Python 3 simulated microblog login
  21. Using Python 3 to make practical software for drawing modification
  22. About HTML (acceptable to Python)
  23. Python集成學習:自己編寫構建AdaBoost分類模型可視化决策邊界及sklearn包調用比較
  24. PYTHON用LSTM長短期記憶神經網絡的參數優化方法預測時間序列洗發水銷售數據
  25. Python Integrated Learning: Writing and Constructing adaboost Classification Model Visualized decision Boundary and sklearn package Calling Comparison
  26. Python prédit les données de vente de shampooing de séries chronologiques en utilisant la méthode d'optimisation des paramètres du réseau neuronal de mémoire à court et à long terme lstm
  27. [zero basics of Python to introduction] a prerequisite for Python preparatory knowledge -- basic coding specification of Python
  28. OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)
  29. [zero basics of Python to getting started] a prerequisite for Python preparatory knowledge -- installing the visualization tool pycharm
  30. The test modifies in micro python
  31. Microphoton experimental circuit board based on mm32f3273 - does not work normally
  32. Run micropathon on mm32f3273 to test performance
  33. Design mm32f3277 micro Python experimental board with SD card
  34. Mm32f3277 corresponding interface files during microphoton migration
  35. Mm32f3277 microphoton experimental board design and software testing
  36. Making and testing mm32f3277 microphoton minimum circuit board
  37. Download mm32-link program automatically with Python simulated mouse
  38. A curriculum of "artificial intelligence Python machine learning and deep learning"
  39. Test the basic functions of mm32 microphoton test circuit board
  40. Test the basic functions of the mm32f3277 micro Python development board flying one by one
  41. Debugging mm32f3277 from zhufei, transplanted with micro Python development board
  42. Recognizing numbers using OpenCV and python
  43. 真的太香了,Python速查表终于出中文版了
  44. Django REST Framework(DRF)教程:快速入门
  45. python django objects filter过滤查询:startswith year
  46. Data encapsulation of Excel test cases in Python
  47. 学员管理系统python
  48. 肝了一夜,8000字概括精髓,pandas必知必会50例!
  49. Python竟然可以画漫画!漫画版的故宫导游图,来袭!
  50. Networkx graph theory Dijkstra algorithm shortest path implementation, Python
  51. Draw a HelloWorld with Python turtle Library
  52. 运行django的服务器内存使用偶尔跳高一点,重启服务马上下来,是内存泄露吧
  53. Basic usage of Python tqdm module in machine learning training
  54. Python -- basic usage method and basic template of argparse module
  55. python-sockertserver并发编程思想
  56. Programmation simultanée du serveur de sockets Python
  57. Vue+Django 旅游网项目 首页前端实现
  58. Classic usage of pandas: iloc and LOC of data filtering
  59. Calendar module of Python time series
  60. A super easy to use Python standard library. It's great to operate directories and files