Data Type and operation, data type operation
Hello world
How to execute a python script
Note
Variable definition
Variable type
Operation expression
Relational Expression
Logical expression
Hello world
All programs start from hello world. Now the first program, hello world:
Cmd output:
- Open cmd
- Enter python and press Enter.
- Input print ('Hello World') and press ENTER
- Enter exit () and press ENTER
- Enter exit and press Enter.
- Work done
Pycharm:
- Create a new project
- Right-click the project and choose new> python File.
- Input print ('Hello World') in the file ')
- Right-click and run <File Name>
- A console will pop up to display the content.
Print:
Print is to print the content on the console
How to execute a python script
- As shown in pycharm, right-click-run <File Name> or click the run button in the toolbar.
- Enter python in the command line, enter the python program, and then enter the items to run, such as the print ('Hello World') above ')
- Create a txt file (or. py file. The default python file is in The py format), and then input python in the command line <absolute path of the File>
Due to the convenience of development tools, the subsequent introduction will be based on pycharm.
Note
The interpreter (which is an amazing thing anyway) translates the code in the file into commands that can be executed by the computer.
Users who want to mark some things for reading files do not need to translate them into commands that can be executed by computers.
The annotation is used.
Comment writing
- Single line comment starting #
- Multi-line comments enclosed in three single quotes
Variable definition
Python is a weak type language, meaning that the type of a variable does not need to be declared before it is defined.
Variable type
Although python is a weak type language, it still distinguishes the types of variables:
- Integer: an integer.
- Floating Point: a decimal point.
- String: simple to understand, that is, a character such as "hello world"
- Boolean: True or False. True indicates True. False indicates False.
Operation expression
Expressions used in python operations:
Addition, subtraction, multiplication, division, Parentheses, power
Addition, subtraction, multiplication, division
For example, a + = 1 is short for a = a + 1.
For example, a-= 1 is short for a = a-1.
For example, a * = 1 is short for a = a * 1.
For example, a/= 1 is short for a = a/1.
Relational Expression
Represents the relationship between two or more variables:
- >,>=: Greater than or equal
- <, <=: Less than, less than or equal
- ! =: Not equal
- =: Equal
The values they compare are either true or False, so the values they compare are the Boolean variables mentioned above. For example, the comparison result of 2> 3 is False, that is, False.
Logical expression
To connect multiple relational expressions, simply connect multiple boolean values and return a Boolean value:
- And: and false
- Or: or, true
- Not: No, reversing true or false
I would like to ask: is it possible to steal a hacker?