Use of annotations and quotation marks
# I'm a line of comments " " Well, I'm also a line of comments " " Print (' Print multiline string-the first line prints multiple lines of string-second line ') Print (" I'm trying to nest in quotation marks ' I'm trying to nest in quotes ") Print (' so coincidentally, I'm also trying to nest in quotes ' I'm also trying to nest in quotes ')
Require user input characters, and string concatenation
Note: User input is a string that needs to be converted as a numeric use: Int (age)
#require user inputName=input ("What ' s your name?") Job=input ("What ' s your job?")#Print out ContentPrint(name,job)#string Stitching Method 1, try not to use, to occupy more than a block of memoryPrint(" "---info of" "+name+" "---Name:" "+name+" "Job:" "+job)#string concatenation Method 2,%s stands for stringPrint(" "---Info of%s---name:%sjob:%s" "%(name, name, job))#string concatenation Method 3Print(" "---Info of {_name}---name:{_name}job:{_job}" ". Format (_name=name,_job=job))#string concatenation method 4Print(" "---Info of {0}---name:{0}job:{1}" ". Format (Name,job))
Analog Linux login, cipher cipher display
Note: This is not a good use in pycharm.
Import # introduction of standard library password=getpass.getpass ("Password:")
If...else Process Judgment
Note: Indentation must be correct because there is no terminator such as {}
if and _password==password: print("Welcome {name}". Format (name=username)) Else : Print ("Invalid username or password")
While loop
Count=0num=15 whileCount<3: Guess=int (Input ("Please a number:")) ifguess==Num:Print("correct!") Break elifGuess>Num:Print("bigger!") Count+=1Continue Else: Print("smaller!") Count+=1ContinueElse: Print("Guess incorrectly for 3 times!")
Infinite loops
while True: name=input ("name:")
For loop
for in range: name=input ("name:") if name == "Bell": breakElse: Print ("notcorrect")
Python 0 Basic Learning-Fundamentals 2-code initial