Learning notes for Python/001 (2018-5-14)

Source: Internet
Author: User

1.Character encoding
ASCLL yards
7,445 characters and characters are included in GB2312;
21,886 characters and characters are included in GBK1.0;
27,484 characters and characters are included in GB18030;
Unicode
Utf-8 is the unified standard of internationalization, (variable long character set) rules in English with 1byte, Chinese characters are expressed in 3bite;

2.comment statements in Python
(1) Single-line comment #----------comment/explanatory statement---------------------
(2) Multi-line Comment "----------comment/explanatory statement---------------------" "or
""----------Comment/Interpretation statement---------------------"" "

3. Three common methods for formatting output
(1)
Name=input ("Name:")
Age=input ("Age:")
Job=input ("Job:")
Salary=input ("Salary:")

Info= ""
------------Info of%s---------------
name:%s
age:%s
jod:%s
salary:%s
"% (Name,name, age,job,salary)
Print (info)

Name=input ("Name:")
Age=int (Input ("Age:")) # is used to force the default string type of age to be converted to an integer type
Job=input ("Job:")
Salary=input ("Salary:")

Info= ""
------------Info of%s---------------
name:%s
age:%d # where the difference lies
jod:%s
salary:%s
"% (Name,name, age,job,salary)
Print (info)

(2)
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, # The difference is that there is no need for one by one correspondence, only choose the function name of the set to correspond well;
_age=age,
_job=job,
_salary=salary)
Print (info)

4. User Name Module
Import Getpass (modules present in the standard library)

Password=getpass.getpass ("Password:")

It is not allowed to run in the Pycharm;

5. Types of circular statements
(1) If-else and If-elif

_passname= ' Penny '
_password= ' abc123 ' # here has already put the username and user password dead, can be optimized in the later learning

Passname=input ("Pass Name:")
Password=input ("Pass word:")

**if _passname==passname and _password==password:
Print ("Welcome {name} loding ...". Format (Name=passname)) # formats (A=B) are designed to introduce variables in the output
Else
Print ("Invarild Pass name or pass word")

Age_of_penny=23
Age=int (Input ("age") # Forced conversion type, input default type is a string character type, forced to convert to int type;
If age_of_penny==age: # note = the difference between = = = Pay special attention to
Print ("You thinking are right")
Elif Age_of_penny < age:
Print ("Thinking smaller ...")
Else
Print ("Thinking bigger ...")

(2) while and While-else

Age_of_penny=23
Count=0
While Count<3: # optimizes the input process,
age = Int (input ("age"))
If Age_of_penny==age:
Print ("You thinking are right")
Break
Elif Age_of_penny < age:
Print ("Thinking smaller ...")
Else
Print ("Thinking bigger ...")
Count+=1
If count==3:
Continue_input=input ("Does want do many guessing?" ")
If continue_input! = ' No ':
Count=0 # continues to initialize count to 0, you can continue to do the above; note the difference between = and = =

Age_of_penny=23
Count=0
while count<3: # optimizes the input process,
age = Int (input ("age"))
If Age_of_penny==age:
Print ("You thinking are right")
Break
Elif Age_of_penny < age:
Print ("Thinking smaller ...")
Else
Print ("Thinking bigger ...")
Count+=1
Else
Print ("You have tried too many times")

(3) For loop

For j in range (10)
Print ("Loop", i)

For-else He was executed after the principal loop for the for, after executing the else

For j in Range (0,10,2) where 2 is the word length,

6Some small areas of Python to note
(1)%s%d

(2)
Print (Type (----))
Print (Type (---), type (str (---)) # prints the converted Type

(3) _name=penny #变量
_name= ' Penny ' #赋值

(4)
Break ends The current loop
Continue jump out of this cycle and into the next cycle

Learning notes for Python/001 (2018-5-14)

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.