python3 study notes a

1, the interactive mode command

Start - " cmd -> cd c: \ -> dir

cd = change directory

dir = view a list of files in the current directory

 

 

cd .. Return to the previous directory

cd ../ .. Return to the parent directory

cd ../../ .. return to the upper level directory

cd ../../../ .. Return to the upper level directory

If we want to switch directories letter, correct usage is cd increased and an intermediate path "/ D" , such as cd / dd:

2 , #C: \ hello.txt .txt extension on behalf of file (extension), used to distinguish file types

.txt Notepad text file

.doc word file

.xls excel file

.ppt PPT file

.exe executable file

.jpg .png .jpeg   pictures

.gif dynamic picture

.pdf PDF file

.mp4 .avi video

.py python file

.java java file

.c .h c source code

.php php file

.js   javascript

 

3 , set the environment variable

 

 

Python added thereto path D: \ python \ Scripts \; D: \ python \;

 

4 , execution py program way :

1. Interactors, shortcomings can not be permanently stored procedures, primarily related to simple grammar test

2. file execution

5 , the Hello world program

print("hello world!")

variable

Variable to store the program operation process some of the results, in order to facilitate later recall

 

Naming variables

1. To descriptive

2. Variable names can only _, numbers, letters, spaces or special characters are not (#? <. , ¥ $ *! ~)

studentNumberPhthon ( hump body )

3. can not Chinese as a variable name

4. does not begin with a number

5. reserved characters can not be used

 

Constant : the same amount of pie = 3.141592653 ....

In py which all variables are variable , so use all uppercase variable names to represent this variable is constant

 

 

6, character encoding

The first table support Chinese called GB2312

 

1980 gb2312 6700+

1995 gbk1.0 20000

2000 gb18030 27000

big5 Taiwan

unicode Unicode encoding supported in all countries and regions

16 ** 2 = 65535 = deposit a uniform character occupies 2 bytes

 

UTF-8 = unicode extended set of variable length coded character set

History of character encoding

Assic -->Gb2312 ->gbk1.0-->gb18030

Assic -->unicode -->utf-8   /utf-16

 

 

Python2.x == Assic default encoding

#!-*- coding:utf-8 -*-

#coding:utf-8

 

python3.x == unicode default encoding

 

 

unicode is backward compatible gb2312, gbk

 

7 comments

Note

Single-line comments with a #

Multi-line comments three by three single or double quotes '' ' content annotated ' ''

8, user input

Input all the data received are strings, times you enter a number, but it will still be treated as a string

Int integer = integer string converted to int , with int (data is transferred)

Str string = string converted into the data string STR (data to be transferred to)

 

Expression if ... else statement

 

 

age_of_princal = 56

 


guess_age = int(input(">>:"))

 

'''
if guess_age == age_of_princal then
print("yes")

 

else print("no")
'''

 

if guess_age == age_of_princal:
print("yes,you got it..")
elif guess_age > age_of_princal:
print("shoud try samller..")


else:
print("try bigger..")

 

Indent error IndentationError: expected an indented block

                            ^

IndentationError: unindent does not match any outer indentation level

SyntaxError: invalid syntax syntax error

tab! = (not equal to) 4 spaces

 

Indentation level must be consistent

Guess you like

Origin www.cnblogs.com/anan369/p/12190902.html