open settings:ctrl+alt+S
Run current code :ctrl+shift+f10
Run the current script :shift+f10
lookup :ctrl+f
Replace :ctrl+R
Global search :ctrl+shift+f
Global replacement :ctrl+sshift+r
revoke :ctrl+z
Counter cancellation :ctrl+shift+z
Indent :tab
Reverse indent :shift+tab
Page turning :pageup and pagedown
Head of line :home
At the end of the line :end
Quick correction :alt+enter
Quick annotation :ctrl+/
Copy code :ctrl+d
Delete the code :ctrl+y
Copy code :ctrl+o
Select a word or code block :ctrl+W
Find documents quickly :ctrl+q
Module or project rename :shift+f6
Insert down :shift+enter
Insert up :ctrl+alt+enter
View view :alt+1
Look at the structure view :alt+7
Quick access code :ctrl+b
Quick view of history :alt+ Left and right
Fast switch :alt+ Up and down
Switch views :ctrl+tab
View the resource file : two shift
See where the method is called :ctrl+alt+h
Look at the parent class :ctrl+u
View inheritance relationships :ctrl+h
input() The function is used to input data , The string in parentheses is a prompt , It is the string that is output before the input data .
input() The value returned by the function defaults to the string type
int() Function first converts a string to an integer
Letter 、 Numbers and underline , And the first character cannot be a number .
Special words cannot be used as variable names
A variable name corresponds to a variable , No two variables have the same variable name
python in , There is no rounding , Rounding refers to discarding the part after the decimal point of the original value
print(num1,num2)
A box has more than one grid , Each item can hold one item . bring print(num1) Join in print(num2) Just use one of the grids to carry things each time , So it needs two times of handling .
and print(num1,num2) It is to use two lattices to pack items at the same time , It can be done in one time .
print A function is a box with an infinite number of boxes .
stay python in , A string of characters between two single quotes or two double quotes is a string . It should be noted that , If you use single quotation marks to represent a string , Then the string cannot contain an apostrophe
text1 = “I‘m a programmer.”
text2 = ‘i’m a programmer.’// No way
+,-,*,/
python3 in , If the result of dividing an integer is not an integer ,python The result of the operation will be stored as floating-point white energy
pow() Find a number n Power
pow(x,y,z)
without z,x Of y Power
If you enter ,x Of y The power divided by z The remainder of ,x**y%z
% Remainder
abds Used to find the absolute value
sqrt For finding the square root
Bitwise AND &
Press bit or |
bitwise exclusive or operator ^
The corresponding digits are different 1, Same as 0
Move left <<
Move right >>
a<<2 :a The binary digits of the whole move to the left by two digits, and then convert back to the decimal number .
If you move left , Then the covered high position disappears , And the vacant position is 0 Not up to .
If you move to the right , Low order hours , The high level becomes 0
use + Number
If you want to add a number to a string , These numbers must also be variables of type string
lower Replace all English characters with lowercase
upper All English characters are capitalized
capitalize: The first alphabetic character of the string becomes uppercase , If the first character is not a letter, it does not change
title Its function is to capitalize the first letter of each word in the string , When words are separated by characters other than letters , Such as good8day, Turn into Good9Day
Escape character
\ Line continuation operator
\ Backslash notation
’ Single quotation marks
" Double quotes
\a Ring the bell
\b Backspace
\e escape
\000 empty
\v Vertical tabs
\r enter
Repeat output string
python This word outputs 3 Time
text = “Python\n”
print(text*3)
Write notes
ctrl+/
perhaps #
python cognizance 0 perhaps null by False, Arbitrary non 0 Value or any non null value is TRUE,
Whether it is equal or not :==
It doesn't wait :!=
Colon sign if The end of judgment
if The code indented below is in true To be operated under
Indenting the same code is called a code block
tab once , Or space around
python No, do``while
python There are only two cycles in :while Statement and for sentence
arr = [1,2,3,4,5,6,7,8,9,10]
for i in range(len(10)):
if arr[i]%5 == 0:
continue
print(arr[i])
List in brackets
The elements in the list are the same as variables , Values can be updated at any time , It can also be used to assign values to other variables .
The elements in the list can be changed
append and Insert These two built-in list Hannah trees
Built in functions append The function of is to insert new elements at the end of the list , The function insert The function of is to insert a new element at the specified index , All the elements behind the element machine originally at this index position are moved backward as .
Remove the elements from the list , There are two functions to choose from :remove and pop.remove The standard format of the function is :list.remove(obj), Removes the first occurrence of a value in the specified list .
pop The standard format of the function is :list.pop(index), Removes an element at an index position in the specified list , It also returns the value of the removed element .
A single :#
Multiple lines : Three single quotes , Three double quotes
Backslash to implement multiline
total = item_one +
item_two +
item_three
stay [],{} or () Multiple lines in , No need to use backslash (\)
Immutable data :Number、String、Tuple
Variable data :List、Dictionary、Set
Positive or negative integers , Without decimal point ,Python3 No, Long type
Integers + decimal
2.5e2=250
true =1
false = 0
Can be added to numbers
a+bj
complex(a,b)
a,b All are floating point type
int()
float()
complex(x): take x Convert to a plural type , The real part is x, The imaginary part is 0
complex(x,y)
+、-、*、/、%、
power ( * *)
//: Divide and conquer : Return to the business certificate section
9//2 = 4
9.0/2.0 = 4.0
Variable = expression
=
+=:c+=a equivalent :c=c+a
-=:c-=a equivalent :c=c-a
= :c=a equivalent :c=c*a
/= : c/=a equivalent :c=c/a
==
!=
<
=
<=
and
or
not
in: Returns if a value is found in the specified sequence true, Otherwise return to false
not in: Returns... If no value is found in the specified sequence true, Otherwise return to false
** The highest
~: Bit reversal
if condition1:
statement_block1
elif condition2:
stationment_block2
while condition:
station_block
condition by false, sign out
It's true , perform statement_block Then calculate again condition Value
Let's judge the expression first , Executing statement
for iterating_var in sequence
statement_block
Terminated
Terminate the loop , Execute next cycle
break、continue In nested statements , It only works for the nearest layer of circulation
pass It's airspace data , Not doing anything , It's like a placeholder
Expression statement ,print() function
Using the write() Method , Standard output files can be used sys.about quote
format :str.format() Function to format the output value
If the output value needs to be converted into a string , have access to repr() perhaps str() Function to implement .
str(): Function returns a user-friendly expression
repr(): Produce an interpreter readable form of expression
s = ‘Hello’
str(s)
repr(s)
"'Hello
python Provides a input() Built in functions , It can read a line of text from standard input
Strings belong to immutable sequences
Short string resident mechanism , For short strings , When assigning it to multiple different objects , There is only one copy in memory , Multiple objects share the copy . However , This does not apply to long strings , That is, long strings do not conform to the resident mechanism . When a long string is assigned to multiple variables , These variables do not share the same memory address .
You can use square brackets to intercept strings
From the first to the last number
find() and rfind() Methods are used to find the position of the first and last occurrence of a string in the specified range of another string , Returns if it does not exist -1
index() and rindex() Method is used to return the position of the first and last occurrence of one string in the specified range of another string , If not, throw an exception
Returns the number of times a string appears in the current string
Search and replace
split() and rsplit() Methods are used to specify characters as separators , Split the current string from left to right or from right to left into multiple strings , And return the list containing the segmentation results .
split() and rsplit() Method also allows you to specify the maximum number of divisions
about split() and rsplit() Method , If you do not specify a separator , Any white space in the string will be considered a delimiter , And the continuous blank symbols are regarded as a separator
However , Explicitly pass parameter assignments split() When using the separator of , The situation is different .
capitalize() Converts the first character of a string to uppercase
Convert the first letter of each word to uppercase
Determines whether the string starts with the specified string
Determines whether the string ends with the specified string
Convert a string to an uppercase string
enter(),ljust(),rjust(), Returns a new string of the specified width , The original string is centered , Left aligned or right aligned format appears in the new string , If the specified width is greater than the string length , Use the specified characters to supplement
zfill() Returns a string of the specified width , To the left, use the character 0 Fill in ,
Remove the specified characters at the beginning or end of the string , Then return a result , But the contents of the original string will not change
‘hello '+‘world’
hello world
“a” in “abcde”
‘abcd’*3