Preparation: Installation python3.6.5
Installing Pycharm
Pycharm Settings Add Template description settings - editor - file and code templates - python script add template content
1. Learn the ritual sense of programming: the first Python program
Print ("Hello world! ")
2. Learning variables
Variables can only be any combination of alphanumeric or underscore, the first character of a variable cannot be a number
A variable in uppercase means a constant
Name= "Peng Huang" Name2=nameprint ("My name is", name) name= "William" Print (name,name2)
Results
My name is Peng Huangwilliam Peng Huang
3. Character encoding
ASCII a total of 255 characters per character accounted for 1bytes
-1980 Chinese gb2312 can represent more than 7k Chinese characters
-1995 Chinese gbk1.0 can represent more than 2w Chinese characters
-2000 Chinese GB18030 can represent more than 27,000 Chinese characters
Unified standards appear Unicode but each character accounts for 2bytes
A scalable character set appears utf-8 English per character in 1bytes per character for 3bytes
Python2.x uses ASCII character encoding by default if you need to declare the set of encodings used in Chinese
#-*-Coding:utf-8-*-
python3.x using UTF-8 encoding set by default
Multiline Comment 3 single quotes or 3 multi-quotes The first addition can also be represented as an entire segment of output
4. Interactive input and three forms of representation
#Author:P Eng huangname=input ("Name:") age=int (Input ("Age:")) #表示为整形输入print (Type (age)) #输出变量类型job =input (" Job: ") Salary=input (" Salary: ") info1=" #第一种形式---------info of%s-----------name=%sage=%djob=%ssalary=%s ""% ( name,name,age,job,salary) info2= " #第二种形式 common format---------info of {_name}-----------name={_name}age={_age}job={_ Job}salary={_salary} ". Format (_name=name, _age=age, _job=job, _salary=salary) info3=" # The third form---------info of {0}-----------name={1}age={2}job={3}salary={4} ". Format (name,name,age,job,salary) print ( INFO3) #可依次打印info1 Info2 Info3 See three ways to achieve results
5. Judgment statement: Interactive Authentication user name password program
#Author:P Eng huang#import getpass #此模块是密码不在明文显示_username = "Huangpeng" _password = "123" username = input ("Username: ") Password = input (" Password: ") #password = Getpass.getpass (" Password: ") #getpass module is not good with pycharm if username = _ Username and Password = = _password: print ("Welcome user {name} login ...". Format (Name=username)) Else: print (" Invalid username or password ")
6. Judgment statement: Guessing numbers
#Author:P Eng huangage_of_oldboy = 56guess_age = Int (input ("Guess Age:")) if Guess_age = = Age_of_oldboy: print ("You go T it! ") Elif guess_age > Age_of_oldboy: print ("Think smaller ...") else: print ("Think bigger..")
7. Loop statement: Guess 3 times the number
#Author:P Eng huangage_of_oldboy = 56count = 0 #引入次数变量countwhile count < 3: guess_age = int (input ("Guess Age:") if Guess_age = = Age_of_oldboy: print ("You Got it!") Break elif Guess_age < age_of_oldboy: print ("Think bigger!") else: print ("Think smaller!") Count +=1 #每次结束都 +1else: print ("You have tried many times ...")
8. Loop statement: Guess 3 times the number is overwritten with a for loop
#Author:P Eng huangage_of_oldboy = 56count = 0for count in range (3): #for改写 guess_age = Int (input ("Guess Age:")) if Guess_age = = Age_of_oldboy: print ("You Got it!") Break elif guess_age > Age_of_oldboy: print ("Think smaller ...") else: print ("thinks bigger..") Count +=1else: print ("You have tried many times ...")
9. Circular statement: Guess 3 times, whether to continue to guess, plus conditional judgment
#Author:P Eng huangage_of_oldboy = 56count = 0while count <3: #此段我存疑, I use for overwrite this segment, I found that for loop does not implement this function, cannot continue to loop, refer to other people's saying: traverse or fixed cycle times with for, indeterminate cycle times with while, pending textual research guess_age = Int (input ("Guess Age:")) if guess_age = = Age_of_oldboy: print ("You Got it!") Break elif guess_age > Age_of_oldboy: print ("Think smaller ...") else: print ("Think bigger..") Count +=1 if Count = = 3: #判断计数器为3时 replay_comfirm = input ("Do want replay? y/n ") #引入交互变量, decide whether or not to continue if replay_comfirm = = ' n ': #如果输入为n, print the game to end printing (" Game Over ") else: #否则重置计数器, continue looping count = 0
Python's first day of study ends, is very basic knowledge, quickly mastered, to follow up on the study
Python Learning-day1