1, programming language classification:
Compiled: (compiled by the compiler to computer-recognized binaries) C \c++ \c# faster than interpreted language
Interpreted: (compiled at run time) python, PHP, Sheel, Ruby, JS, Java
Scripting language: Refers to this language only a single function such as Sheel (run only in the Linux environment), JS
2, Python2 and Python3:python2 belong to the excessive period, the last choice Python3
3. Pychram Tools for writing Python language
To submit code to coding.net in Pycharm: file>setting>version Control >git Select the git installation directory. Click OK
In the VCs >checkout from Version control>git in the popup dialog box, fill in the URL address in coding.net, then select a saved file address and click Clone to
You can then create a new file or create a new Python file and then select
Select commit and push in the pop-up prompt box
4. Character Set:
Set up a set of letters, numbers and other characters into the computer recognizable set of 2, with ASCII code, GBK, Unicode, UTF-8 and other character set encoding
5. Variables:
Static language: You need to define the type before defining the variable, Python does not need to define the type, directly "=" to define
Variable name to see the name of the understanding
Variable names can only be any combination of letters, numbers, or underscores
The first character of a variable name cannot be a number
The following keywords cannot be declared as variable names
| 123 |
[ "and" , ' as ' , ' assert ' , ' break ' , ' class ' , ' Continue ' , ' def ' , ' del ' , ' elif ' , < Span class= "crayon-s" > ' Else ' , ' except ' , ' exec ' , ,&NBSP; ' For ', ' from ' , ' global ' , ' if ' , ' import ' , ' in ' , ' is ' , ' Lambda ' , ' not ' , ' or ' , ' pass ' , ' print ' , ' raise ' , ' return ' ,&NBSP; ' Try ', ' while ', ' with ', ' yield '] |
6, String type use ', single and double quotation marks can be, the string inside a single quotation mark outside with double quotation marks; the single and double quotation marks in a string use 3 quotation marks
3 quotation marks with multiple lines of comment function
Puthon 2 Character set for ASC code does not support Chinese, need to add coding=utf-8 at the head of code
7. Program Exercise:
Input and output:
Python2 default Character set is ASCII code, python3 default is Unicode, if need python2 support Chinese can add Coding=utf-8 in header
#username =input (' Please enter user name ')
#password =input (' Please enter password ')
#if username== ' Niuhanyang ' and password== ' 123456 ':
# print (' Welcome ')
#else:
# print (' Please re-enter ')
Conditional judgment
# equals = = Not equal to = = greater than > less than < greater than or equal to >= less than or equal to <=
#input接受的都是str类型
# #int Forced type conversions
"' Score=input (' Please enter your score: ')
Score=int (Score)
If score<60:
Print (' fail ')
Elif score >= and score < 80:
Print (' Pass ')
Elif score>=80 and score<90:
Print (' good ')
Else
Print (' excellent ')
‘‘‘
#sex =input (' Please enter your gender: ')
#if sex== ' male ' or sex== ' female ':
# print (' OK ')
#else:
# print (' incorrect input ')
Cycle
#for
#while need to define a counter
#continue结束本次循环, go to the next cycle
#bresk End Loop
#count =0 #计数器
#while count<10:
# print (' hahaha haha ')
# #count =count+1
# count+=1
# break
#else: #结束之后执行
# print (' End ')
#count =0
#while count<3:
# username = input (' Please enter user name: ')
# password = input (' Please enter password: ')
# if Username = = ' Niuhanyang ' and password = = ' 123456 ':
# print (' Welcome ')
# break
# #continue (here if there is a problem with continue, it will always loop)
# Else:
# print (' account/password wrong! ')
# count+=1
#else: # # (#结束之后执行)
# print (' Excessive number of errors ')
#猜数字游戏
#import random
#random_num =random.randint (1,100)
#print (Random_num)
#count =0
#while count<7:
# count + = 1
# Num=int (Input (' Please enter your guess number: ') ")
# if Num>random_num:
# print (' You guessed too big ')
# continue
# elif Num<random_num:
# print (' You guessed too small ')
# continue
# Else:
# print (' Congratulations on your guess, the answer is: ', random_num)
# break
# #for Loop Auto +1
# for I in range (10):
# print (' HHH ', i)
# import Random
# Random_num=random.randint (1,100)
# for I in range (3):
# num = Int (input (' Please enter the number you guessed: ') ')
# if num > Random_num:
# print (' You guessed too big ')
# elif Num<random_num:
# print (' You guessed too small ')
# Else:
# print (' Congratulations on your guess, the answer is: ', random_num)
Formatted output: Formats the output as one
Method:
#1, by adding two strings, int and string cannot be added directly
# 2,%s is a placeholder, several are followed by several variables,%s corresponds to a string,%d int,%f corresponds to a floating-point type, leaving a few decimals such as 2 decimal places, then%.2f
#3, by format
See the following procedure for details:
#for I in range (5):
# username=input (' Please enter name: ')
# time= ' December 17, 2017 17:20 '
# #字符串格式化方法
#print (username+ ', Welcome to ' + ' time is ' +time ')
#print ('%s, welcome, time is:%s '% (username,time))
# Print (
# ' {}, welcome, time is: {} '. Format (username,time)
# )
#print (
# ' {name}, welcome, time is: {date}, now the time is {date} '. Format (name=username,date=time) #3, format another way
#)
Python Learning-01