1.python Introduction
2. Installation
3. First Python program
4. Variables
5. User input
1.python Introduction
According to a study published by IEEE Spectrum, Python, ranked third in 2016, has become the world's most popular language this year, with C and Java ranked second and third respectively. This shows that Python will be the future language
2. Installation
First we go into the https://www.python.org to download the corresponding version of python2.7 or python3.5 to your system
3. First Python program
Run Python and set up a Hello,word program.
4. variable \ character encoding
Variables is used to store information to is referenced and manipulated in a computer program. They also provide a labeling data with a descriptive name, so we programs can be understood more clearly by the RE Ader and ourselves. It's helpful to think of variables as containers, that's hold information. Their sole purpose is to label and store data in memory. This data can and is used throughout your program.
declaring variables
123 |
#_*_coding:utf-8_*_ name = "Alex Li" |
The code above declares a variable named: Name, and the value of the variable name is: "Alex Li"
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 ']
Assigning values to variables
12345678 |
name = "Alex Li" name2 = name print (name,name2) name = "Jack" print ( "What is the value of name2 now?" ) |
Notes
When the line stares: # is annotated content
Multiline Comment: "" "Annotated Content" ""
5. User input
1234567 |
#!/usr/bin/env python #_*_coding:utf-8_*_ #name = raw_input("What is your name?") #only on python 2.x name = input ( "What is your name?" ) print ( "Hello " + name ) |
When entering a password, if you want to be invisible, you need to take advantage of the Getpass method in the Getpass module, namely:
12345678910 |
#!/usr/bin/env python # -*- coding: utf-8 -*- import getpass # 将用户输入的内容赋值给 name 变量 pwd = getpass.getpass( "请输入密码:" ) # 打印输入的内容 print (pwd) |
Python Learning Path Basics 01