Python installation
Go to the official website to download the installation package and choose the Python version you need. Now Python has already entered the 3.x era, it is best to choose 3.x version. The version of 2.x is not updated and will stop service in 2020.
Installation process The next step is fine, but remember your installation path. For subsequent configuration of the Python environment variables.
Use Python-v to see if the Python installation is successful and current version in the DOS interface.
The first Python program
Output Hello World
1, can be output in Python's own idle
Print ("Hello world!")
2. You can also create a new document example:FitstPythonProj.py
The suffix of the document must be a. py format that is known by the Python program
Enter Python firstputhonproj.py in the DOS interface
Python variables
Python does not need to be in other languages (such as C,c++,java, etc.), before use, you need to declare the variable type,
Example: String name= "Jackson"in Java; the type of name is a character type. In Python, the direct
name= "Javason" does not need to be declared, Python will automatically match us.
rules for variable definitions:
- Variable names can only be any combination of letters, numbers, or underscores
- The first character of a variable name cannot be a number
- The following keywords cannot be declared as variable names
[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']
User input
name
=
input
(
"What is your name?"
)
print
(
"Hello "
+
name )
Need to hide input number is can import module Getpass
import
getpass
# 将用户输入的内容赋值给 name 变量
pwd
=
getpass.getpass(
"请输入密码:"
)
# 打印输入的内容
print
(pwd)
Loop statement:
The simplest loop 10 times
for
i
in
range
(
10
):
print
(
"loop:"
, i )
function range
prototypes: Range (start, end, scan):
parameter meaning : Start: Count starts from start. The default is starting from 0. For example, range (5) is equivalent to range (0, 5);
End: The technology ends with end, but does not include end. For example: Range (0, 5) is [0, 1, 2, 3, 4] No 5
Scan: The distance between each hop is 1 by default. Example: Range (0, 5) is equivalent to range (0, 5, 1)
Python Learning Path--day 1