First, HelloWorld
#! /usr/bin/env python
#-*-Coding:utf-8-*-
Print ("helloworld!")
Second, user interaction
#!/usr/bin/env python
#_*_coding:utf-8_*_
name
=
input
(
"What is your name?"
)
print
(
"Hello "
name )
When entering a password, if you want to be invisible, you need to take advantage of the Getpass method in the Getpass module, namely: importgetpass
# 将用户输入的内容赋值给 name 变量
pwd
=
getpass.getpass(
"请输入密码:"
)
# 打印输入的内容
print
(pwd)
#!/usr/bin/env python
# -*- coding: utf-8 -*-username = input ("username:")Password = getpass.getpass ("Password:")print ("Username,password")#在pycharm中会执行不了, but can be performed in a Linux environmentThird,
string formatted output
name
=
"emily"
print
"i am %s "
%
name
#输出: i am emily
PS: string is%s; integer%d; floating-point number%f
Iv. expression If......else
#!/usr/bin/env python
# -*- coding: utf-8 -*-
_username = ' Emily '_password = ' abc123 'username = input ("Username:")
Password = input ("Password:")
If _username = = Username and _password = = password:
Print ("Welcome user {Name} login ...")
Else
Print ("Invalid username or password!")Five. While statement
A = 30
Count = 0
While Count <3:
b = Int (input ("A:"))
If a = = B:
Print ("Yes")
Break
Elif A>b:
Print ("small")
Else
Print ("Big")
Count +=1
Else
Print ("You have tried too many times. Fuck off ")
VI. For statement
For I in range (10):
Print ('------', i)
For j in Range (10):
Print (j)
If j>5:
Break
The first section of Python learning notes