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

Why_ does_ it_ work 2021-11-25 15:32:12
learn python articles reading online

To understand the python The download You don't have to watch online classes to learn python The article ( The first day )_Why_does_it_work The blog of -CSDN Blog

Today officially entered python Learning from :

python Its grammar is relatively simple , First



type Functions

Input and output




We said Coding for so long , How much do you know about running ?_Why_does_it_work The blog of -CSDN Blog

Programs are used to process data , Variables are used to hold data , So in python Code for ( Program ) in , How variables are used :

1. Definition of variables

python The definition of language variables is relatively simple , But in python Must assign a value to a defined variable in , Only by assigning this variable will the format be created : Variable name = value


Because it's followed by a string , So the string should be quoted

The above code only needs to enter vx You can output it directly 123456, If you need to output directly 12356, Then we need to use printf function ( take print The functions inside are output to the console


2. Using variables

After the variable definition is complete , Variables can be used directly , But how to define the variables to be calculated ?


As shown in the above code , It can be defined by other variables

3. Defining a variable in memory requires

Variable name , Data saved by variables , The type of data the variable holds , And the address of the variable

4. Variable type

stay python In language , There is no need to add data types , Because in python The interpreter will accurately deduce the correct data type according to the right side of the assignment

The string needs to be added when assigning a value to a variable ”“    The string type is str

Integer types don't need to add anything , Just follow the numbers     The integer type is int

Boolean types don't need to add anything ( Boolean types are true and false types )    The boolean type is bool( No 0 It's all true 1)

Floating point types don't need to add anything     Floating point type is float

To sum up

stay python There are two types of statements , One is the number type , One is a non numeric type

Numeric type Including integer type (int) Floating point type (float) Boolean type (bool) There is also a plural type (complex)

Non numeric type Including strings , list , Tuples , Dictionaries

int(x) The function can convert a string to an integer

float(x) The function converts a string to a decimal

Strings can only be added and spliced , You can't multiply. You must convert the string to decimal and integer

type Functions

Analyze the data type of the variable , It has to be said that type function , Main forms

type( Variable )

The purpose of this function is to determine the function type , After defining the variables , Input type Function can output the data type of this variable

Input and output

1. Input

Input Is to use the code to obtain the information entered by the keyboard , stay python Need to use input function , The function is to obtain keyboard input information

input(" Please enter your password ")
Please enter your password :123546
obtain :123456

input The function is right there c Language equals printf+scanf,printf In parentheses

If we want to use input The keyboard input is saved by assignment

vx=input(" Prompt information ")

Because in python You can only use numeric type for multiplication, not string type for multiplication , So we need to convert

price=float(input(" price is "))

2. Output

Format output

I want to output data when I output text , You need to use formatted output

%s  Output string

%d  Output integer     %06d( If you want to output a six bit integer, there is 0)

%f  Output floating point number    %.2f Indicates two digits after the decimal point of the output

%%  Output %

This and c The language situation is similar

print(" My name is %s, Please take good care of me ”%name)


keyword Is in the python Identifiers already used in the language

1.import  tool kit

import You can use the toolkit , You can use the keywords in the toolkit


Arithmetic operator
+     Add , Add two objects ;    a+b The output is 8
-     reduce , Subtract two objects or get a negative number ;    a-b The output is 4
*     ride , Multiply two objects or return a string that is repeated several times ;    a*b The output is 12
/     except , Two objects divide ;    a/b The output is 3.0
%     modulus , Find the remainder of division ;    a%b The output is 0
**     power - return x Of y The next power     a**b The output is 36
//     Divide and conquer - Take down the whole number close to the quotient     a//b The output is 3

Comparison operator
==     be equal to , Compare objects for equality ;    (a == b) return False;
!=     It's not equal to , Compare two objects for inequality ;    (a != b) return True;
>     Greater than , return x Is it greater than y;    (a > b) return False;
<     Less than , return x Is less than y;    (a < b) return True;
>=     Greater than or equal to , return x Greater than or equal to y;    (a >= b) return False;
<=     Less than or equal to , return x Less than or equal to y;    (a <= b) return True;

Assignment operator

Operator      effect      example
=     Simple assignment operators     c = a + b take a + b The operation result of is assigned as c ;
+=     Addition assignment operator     c += a Equivalent to c = c + a ;
-=     Subtraction assignment operator     c -= a Equivalent to c = c - a ;
*=     Multiplication assignment operator     c *= a Equivalent to c = c * a ;
/=     Division assignment operator     c /= a Equivalent to c = c / a ;
%=     Modulo assignment operator     c %= a Equivalent to c = c % a ;
**=     Power assignment operator     c * *= a Equivalent to c = c ** a ;
//=     Integer division assignment operator     c //= a Equivalent to c = c // a ;
:=     Walrus operators , You can assign a value to a variable inside an expression .    

An operator
&     Bitwise operators , Two values involved in the operation , Both corresponding bits are 1 when , The result of this bit is 1, Otherwise 0;
|     bitwise or operator , One of the corresponding two binary bits is 1 when , The result bit is 1;
^     bitwise exclusive or operator , When two corresponding bits are different , The result is 1;
~     Bitwise negation operator , Invert every bit of data , Namely the 1 Turn into 0, hold 0 Turn into 1;
<<     Left move operator , All the binary bits of the operand are shifted to the left by several bits , from "<<" The number on the right specifies the number of digits to move , High level discard , Low complement 0;
>>     Move right operator , hold ">>“ Each binary of the left operand is shifted several bits to the right ,”>>" The number on the right specifies the number of digits to move

Logical operators
Operator      expression      effect
and                           x and y     And , x by False,x and y return x Value , Otherwise return to y Calculated value ;
or                               x or y     or ,x by True,x or y return x Value , Otherwise return to y Calculated value ;
not                              not x     Not ,x by True, return False , x by False, return True

I'm going to class , That's it , By the end c After the grammar of the language python It will be easy to understand , Write the next one after class , The next one is python The statement module of !!

本文为[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