Python Fundamentals
A programming language
What is a programming language?
The above-mentioned expression that can be recognized by computer is programming language, which is the medium of communication, and programming language is the medium of communication between programmer and computer. In the world of programming, computers are more like slaves of human beings. The purpose of human programming is to command slaves to work.
The above-mentioned expression that can be recognized by computer is programming language, which is the medium of communication, and programming language is the medium of communication between programmer and computer. In the world of programming, computers are more like slaves of human beings. The purpose of human programming is to command slaves to work.
What is programming?
Programming means that a programmer writes his own thought process according to the grammatical style of a programming language according to his needs, and the output is a file containing a bunch of characters.
Programming means that a programmer writes his own thought process according to the grammatical style of a programming language according to his needs, and the output is a file containing a bunch of characters.
Stress:
A program is no different from an ordinary file before it runs. Only when the program runs, the characters written in the file have specific grammatical meanings.
A program is no different from an ordinary file before it runs. Only when the program runs, the characters written in the file have specific grammatical meanings.
Two Computer Components
CPU: Central Processor Unit (CPU) is a very large scale integrated circuit, which is the operation and control core of a computer. Its function is mainly to interpret computer instructions and process Data in computer software. It mainly includes ALU, Cache and Bus which realizes the connection between them.
Memory: Memory, also known as memory memory and main memory, is used to temporarily store operational data in the CPU and exchange data with external memory such as hard disk.
External memory: External memory refers to a memory other than computer memory and CPU cache, which can generally save data after power failure. Common external memory includes hard disk, floppy disk, CD-ROM, U-disk, etc.
Input device: A device that inputs data and information to a computer. It is a bridge between computer and users or other devices, and one of the main devices for information exchange between users and computer systems.
Output equipment: It is the terminal equipment of computer hardware system, which can display the data or information of various calculation results in the form of numbers, characters, images, sounds and so on.
CPU: Central Processor Unit (CPU) is a very large scale integrated circuit, which is the operation and control core of a computer. Its function is mainly to interpret computer instructions and process Data in computer software. It mainly includes ALU, Cache and Bus which realizes the connection between them.
Memory: Memory, also known as memory memory and main memory, is used to temporarily store operational data in the CPU and exchange data with external memory such as hard disk.
External memory: External memory refers to a memory other than computer memory and CPU cache, which can generally save data after power failure. Common external memory includes hard disk, floppy disk, CD-ROM, U-disk, etc.
Input device: A device that inputs data and information to a computer. It is a bridge between computer and users or other devices, and one of the main devices for information exchange between users and computer systems.
Output equipment: It is the terminal equipment of computer hardware system, which can display the data or information of various calculation results in the form of numbers, characters, images, sounds and so on.
Installation and use of three python s
1. Install python interpreter
2. Install pycharm editor
3. Write python code and print hello world!
1. Install python interpreter
2. Install pycharm editor
3. Write python code and print hello world!
The code is as follows:
print('hello world!')
#Print the contents in''
Four variables
Variable quantities.
Variable value: A memory address that is actually stored in memory.
Variable Name: Used to bind to the value of a variable.
Assignment = sign: Binding the value of a variable to its name.
Naming specification for variables
1. Naming Hump: Sticky Fingers
2. Underline naming: Sticky_Fingers (commonly used in Python)
Variable Name Definition Specification
1. Start with an English letter or underscore (not a number)
2. Keyword cannot be named
For example,'and','as','assert','break','class','continue','def','del','elif', etc.
Defining a bad way to name a variable
1. Don't name it in Chinese
2. Naming length is too long
3. Undesirable Naming of Variables
name = 'Sticky_Fingers'
# Name is the variable name and''is the variable value, which means assigning the value in'' to the variable.
gold English letter beginning
_ experience Underline the beginning
4 The Dream # Error
Three characteristics of defining variables:
id #Address used to represent the value of a variable in memory type #Types of variable values value #Values of variables
Five Constants
Invariant quantities, named in full capitals. Essentially, it is also a variable. In mechanism, it is not impossible to modify it. It is stipulated that all capitalized variables are called constants and cannot be modified.
Invariant quantities, named in full capitals. Essentially, it is also a variable. In mechanism, it is not impossible to modify it. It is stipulated that all capitalized variables are called constants and cannot be modified.
Naming Specification: Variable names are capitalized
PLATINUM = 'Platinum'
Six Users Interacting with Programs
Input:
input()
Input:
input()
Output:
print()
print()
standname = input('Your stand-in name:') print(standname)
7 Format Output
Dear User, Hello! You have deducted 99 yuan from this month's telephone bill, leaving 0 yuan.
Dear User, Hello! You have deducted 99 yuan from this month's telephone bill, leaving 0 yuan.
# A placeholder is used to replace a character in a position in a string.
Placeholder:
% s: Any type can be replaced
% d: Number types can be replaced
% s: Any type can be replaced
% d: Number types can be replaced
Example:
str1 = 'Honorable users, hello! Your telephone bill for this month is deducted%s Yuan, left%d Yuan.' %('Nonacosa',44) print(str1) #44 Can't add'',%d Instead of numbers, add numbers.''It will then represent a string.
Eight basic data types
1. Number type:
Integer: int
1. Number type:
Integer: int
Floating point type: float
#int geniusboy = int(16) print(geniusboy) print(type(geniusboy)) #float height = float(1.75) print(height) print(type(height))
2. String type
Role: Descriptive information such as name, gender, nationality, address, etc.
Role: Descriptive information such as name, gender, nationality, address, etc.
Definition: Within single quotation marks \ double quotation marks three quotation marks, it consists of a string of characters.
stand = 'Gold Experience'
Priority operation:
1. Value by index (forward + reverse): only
#1.Value by index(Forward+Reverse fetching) #Forward print(stand[0]) #G print(stand[5]) #E #reverse print(stand[-1]) #e
2. Section (head and tail, step length)
#2.Section print(stand[0:6]) #Gold Ex #step
print(stand[0:14:2]) #Gl xeine
3. Length len
#3.length print(len(stand)) #14
4. Membership operations in and not in
#4.Membership operation in and not in print('Gold' in stand) #True print('Gold' not in stand) #False
5. Remove the blank strip
#5.Remove blanks #Removes spaces on the left and right sides of the string stand = ' Gold ' print(stand) print(stand.strip()) #Gold #Remove the specified string stand1 = '?Gold!' print(stand1.strip('!').strip('?'))
6. Segmentation split
#6.segmentation #According to the space in the variable value, the obtained part is stored in it.[]List print(stand.split(' ')) #['Gold','Experience']
7. Cycle
#7.loop #Traverse the string and print each character for line in stand: print(line)
Need to master:
1,strip,lstrip,rstrip
stand =' Gold ' #1.strip,lstrip,rstrip print(stand) print(stand.strip()) #Remove both sides of the blank print(stand.lstrip()) #Remove the left space print(stand.rstrip()) #Remove the right space
2,lower,upper
#2.lower,upper #Convert to lowercase print(stand.lower()) #gold #uppercase print(stand.upper()) #GOLD
3,startswith,endswith
#3.startswith,endswith print(stand.startswith(' ')) #True print(stand.endswith('d')) #False
4. Three Plays of Form
#4.format Three uses of formatted output str1 = 'Gioruno·Jobana has%s A dream is to be%s' %(1,'gang star') #Mode 1: Format according to position order print('Gioruno·Jobana has{}A dream is to be{}'.format(1,'gang star')) #Mode 2: Format according to index print('Gioruno·Jobana has{0}A dream is to be{1}'.format(1,'gang star')) #Mode 3: Name Formatting print('Gioruno·Jobana has{number}A dream is to be{who}'.format(number=1,who='gang star'))
5,split,rsplit
6,join
#6.join StringBuilder #String splicing is allowed only print(' '.join(['Gold','Experience','\b—Giorno Giovanna']))
7,replace
#7.String substitution str1 = 'AriAriAriAri...Arrivederci!' print(str1) str2 = str1.replace('Ari','Ora').replace('Arrivederci','Ora') print(str2)
8,isdigit
#8.Determine whether a string is a number choice = input('Did you drop the gold sword or the silver sword? One.Golden Sword 2.Silver Sword 3.I am an honest man.') print(choice.isdigit())