basis
1: The first statement
print("HelloWorld")
2: two execution mode
python interpreter py file path
python interpreter into the
And get real-time input into the results
3: Path interpreter
in linux
#!/usr/bin/env python
4: code #! - * - coding: utf8 - * -
python3 without adding
python2 each file as long as the Chinese appear, the head must be added.
5: perform an operation
Reminder User input: the user name and password.
Obtain a user name and password, detection: YHM = username, password = 123
Correct: Log success
Error: Logon failure
Code:
a = input ( "Please enter your user name:")
b = the INPUT ( "Please enter your password:")
IF A == "YHM":
IF b == "123":
Print ( "Login successful")
the else:
Print ( "login failed")
the else:
Print ( "login failed")
input usage, always wait until the user enters a value for value, it will be assigned to a variable input
6: variable name
--letter
--digital
- Underline
ps: figures do not begin with
It can not be keywords
最好不要和python内置东西重复。
7:字符串(引号):
name1 = "******"
name2 = '''****'''
name3 = """***"""
加法:
n1 = "wo"
n2 = "ta"
n3 = n1+n2
结果:wota
乘法:
n1 = "wo"
n2 = n1*4
结果:wowowowo
8:数字:
a = 20
加、减、乘、除、次方(**)、求余(%)、商(//) 9:循环:(在python中注意缩进) (一)打印:1 2 4 5 6 8 9 10 i = 1 while i<=10 : if i ==1 : print(i,end = " ") else: print( ) i +=1 #(在循环中必须有破坏循环条件的语句) (二)打印:1到100 i = 1 while i <=100 : print(i) i +=1 (三)求1-2+3-4+5到99 i = 1 j = 1c = 0 while i<=99 : if i%2==0: j = -1 else: j = 1 c = c + i*j i +=1 print(c) #如有错,欢迎评论交流