0 Basics Start Learning python

Source: Internet
Author: User

variable rules : In Python, variable names cannot have special characters and numbers beginning with some keywords in python, you can start with an underscore, in Python, variables are supported in Chinese, but try not to use Chinese, why? Because it will make you look too low, like a shanbao programmer, using pinyin is the same, but this is a challenge for me, in the use of SQL I use a large number of pinyin.

The uppercase representation is a constant.

encoding : The most basic is the ASCII code, and the Chinese GB series, the majority of the current use of the UTF-8 scheme, UTF-8 can be very good to solve the compatibility of English and Chinese, an English occupies 2 bytes, a Chinese occupies 3 bytes;

Note : There are two types of

1. The current line, preceded by #, represents the behavior comment.

2. Add 3 single or 3 double quotation marks to indicate that the paragraph is a comment, that is, a multiline comment.

In Python, single and double quotes work the same way. = is an assignment, = = equals.

user input:input

Example: Name=input (' Name: ')

Ways to print variables

1. Using %s

Name=input (' Name: ')
Age=input (' Age: ')
Job=input (' Job: ')
Salary=input (' Salary: ')
Info= ""
-----------------Info of%s--------------
name=%s
age=%s
job=%s
salary=%s
"% (name,name,age,job,salary)
Print (info)

2. Formatted output: Format

Cases:

Name=input (' Name: ')
Age=input (' Age: ')
Job=input (' Job: ')
Salary=input (' Salary: ')
Info= ""
-----------------info of {_name}--------------
Name={_name}
Age={_age}
Job={_job}
Salary={_salary}
". Format (_name=name,
_age=age,
_job=job,
_salary=salary)
Print (info)
Both of the above can be achieved on the output of the variable printing, the first operation is simple, the second looks clear structure.

Importing libraries: Import
#密文库

Conditional judgment
If Else
_age=60
Print (Type (_age))
Age=int (Input ("Guess Age:"))
If Age>_age:
Print (' Guess big ')
Elif Age<_age:
Print (' Guess small ')
Else
Print (' You guessed it right ')
When making this statement, pay attention to the data type, and the data type that appears is not necessarily the actual data type, which is what the boss says in class, and he feels it in practice.

Cycle

While

Jump out of the loop .
Continue
out the remaining statements of the current loop
count () counts the number of occurrences of a character
Range () count
Example: Range (10) is from 0 to 10, does not contain 10, and the default step is 1. Range (1,10,3) refers to 1 to 10, excluding 10, step 3.

While loop
_password=123
Count=0
While count<3:
Password = Int (input (' Please enter your Net-silver password: '))
If Password==_password:
Print (' Login successful ')
Break
Elif Password!=_password and Count==0:
Print (' Input password error ')
Elif Password!=_password and Count==1:
Print (' You've lost two times, and then you're locked in the wrong place ')
Else
Print (' Your account has already been frozen ')
Count +=1
For loop
For I in range (3):
_password = Int (input (' Password: '))
If Password==_password:
Print (' Login successful ')
Break
Else
Password!=_password
Print (' Password input error ')
Else
Print (' Password is locked ')

Loop nested Loops
_password=123
Count=0
While count<3:
Password = Int (input (' Please enter your Net-silver password: '))
If Password==_password:
Print (' Login successful ')
Break
Elif Password!=_password and Count<2:
Print (' Input password error ')
Else
Print (' You've already lost three times ')
Count +=1
If count==3:
Countne=input (' Would you like to continue typing? ')
If countne= ' n ':
Count==0
I learned this last week, and there are a lot of mistakes in syntax formatting that you need to practice.


0 Basics Start Learning python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.