Python learning day 2, python Day 2
- Memory address query for python Variables
#!/usr/bin/env python# -*- coding:utf-8 -*-name = "zhang"name1 = "frank"id (name)
- Process Control and indentation
If condition:
Execute the next statement (content)
Content 2
Else:
Content 3
Content 4
The indentation must be the same in python, or four spaces are used. It is strongly recommended to use four spaces instead of indentation. Because it can be used in different system environments. There is no program incompatibility problem caused by indentation.
The difference between = and = is that an equal sign is a value assignment and two equal signs are a comparison.
#! /Usr/bin/env python #-*-coding: UTF-8-*-# The following program judges name1 = raw_input ("Enter the first user name ") name2 = raw_input ("enter the second user name") if name1 = name2: print ("Congratulations, you have written it") print ("You are not stupid -- good by") else: print ("Enter again ")
Simple user name and password logon Program
#! /Usr/bin/env python #-*-coding: UTF-8-*-# The following program judges name = raw_input ("Enter the user name ") pwd = raw_input ("enter the password") if name = "zhangkun" and pwd = "123 ": # if name = "zhangkun" or pwd = "123 ":
Print ("congratulations, logon succeeded") print ("You are not stupid -- good by") else: print ("Logon Failed ")
Multiple judgment syntaxes
If condition 1:
Elif condition 2:
....
Elif Condition 3:
23444444
Else:
Ssssss
Multiple conditions can be False, True, <,>, <>, =, a = B and B = c, a = B or v = w, a! = B
#!/usr/bin/env python#-*- coding:utf-8 -*-name = raw_input("plase input a name:")if name == "zhangk": print ("good")elif name == "frank": print("NO!!!,name is a english name ")elif name == "yes": print ("you input yes is not ok")elif name == "no": print ("input no is not ok too!!!!!!!!!")else: print ("you name do you konw? you is a SB")
- While loop statement usage
While condition:
......
After the conditions are met, the cyclic body is introduced. If the condition is not met, it is an endless loop.
Code block
#! /Usr/bin/env python #-*-coding: UTF-8-*-a = raw_input ("plase input a num:") B = 1if a = "3 ": while B <10: print str ("cyclically") + a B = B + 1 else: print ("He dear TMD ")
How to make the program run once a second when the loop body is executed? Here a time module is used.
#! /Usr/bin/env python #-*-coding: UTF-8-*-import timea = raw_input ("plase input a num:") B = 1if a = "3 ": while B <10: print str ("cyclic") + a time. sleep (1) B = B + 1 else: print ("He MD S ")
Write a small program that needs to convert the string to the integer type and then the integer to the string type. Let's try to run the program to input 9. What is the result?
#! /Usr/bin/env python #-*-coding: UTF-8-*-import timenum = raw_input ("plase into a numbles >>>") num = int (num) if num <40: while num <10: print ("cyclically") + str (num) + ("times") num = num + 1 time. sleep (1) else: print ("I'm geek ")