One,. PYc is what a ghost:
PYC files are actually a persistent way to save Pycodeobject.
Ii. Types of data
1. number:
2 is an example of an integer.
Long integers are just larger integers.
3.23 and 52.3E-4 are examples of floating-point numbers. The e tag represents a power of 10. here, 52.3E-4 means 52.3 * 10-4.
( -5+4j) and (2.3-4.6j) are examples of complex numbers, where -5,4 is a real number, j is an imaginary number, and what is a mathematical representation of a complex number?
int (integral Type)
On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807
Long (integer)
Unlike the C language, Python's long integers do not refer to the positioning width, that is, python does not limit the size of long integer values, but in fact, because of limited machine memory, We use a long integer value can not be Infinite.
Note that, since Python2.2, python automatically converts integer data to long integers if an integer overflows, so it does not cause any serious consequences if you do not add the letter L after long integer Data.
Float (float Type)
A floating-point number is used to process real numbers, which are numbers with Decimals. Similar to the double type in c, accounting for 8 bytes (64 bits), where 52 bits represent the bottom, 11 bits represent the exponent, and the remaining one represents the Symbol.
Complex (plural)
The complex number consists of real and imaginary parts, the general form is x+yj, where x is the real part of the complex, and Y is the imaginary part of the complex, where x and y are real numbers.
Note: small number pools exist in Python:-5 ~ 257
#复数, the production environment is used relatively little.
Python 2.7 has integral and long integer types:
>>> (2)-1
1
>>> (2**31)-1
2147483647L
>>>
>>> type ((2**30)-1)
<type ' int ' >
>>> type ((2**31)-1)
<type ' Long ' >
>>>
Python 3.x does not have integral and long integer types:
>>> type ((2**30)-1)
<class ' int ' >
>>> type ((2**31)-1)
<class ' int ' >
>>>
2. Boolean value
True or False
1 or 0
>>> 1 is True
False
>>> 0 is False
False
>>> 0 is True
False
3. string
"hello world"
string concatenation of all Evils:
The string in Python is represented in the C language as a character array, and each time a string is created, it needs to open a contiguous space in memory, and once you need to modify the string, you need to make room again, and the Evil + sign will re-open up a space within each occurrence.
>>> name = ' Luchuan '
>>> Print ("my name is" + name + "and You?")
My name is Luchuan and you?
>>>
#这等于三块内存空间
String formatted output
Name = "luchuan"
Print "i am%s"% name
#输出: I am Luchuan
PS: string is%s; integer%d; floating-point number%f
String Common Functions:
Remove whitespace
Segmentation
Length
Index
Slice
1) Strip Remove Blank
Username = input ("user:")
If username.strip () = = ' Alex ':
Print ("welcome")
2) Split Split
Name = "alex,jack,rain"
name2 = Name.split (",")
Print (name2)
3) Join string together
Name = "alex,jack,rain"
name2 = Name.split (",")
Print ("|". Join (NAME2))
4) "in name to determine if there are no spaces
Name= "alex li"
Print ("in Name")
5) Capitalize first Letter capital
Name= "alex li"
Print (name.capitalize ())
6) Format formatted
msg = "Hello, {name}, It ' s been a long {age} since last time Sopke ..."
MSG2 = Msg.format (name= ' xiaoming ', age=33)
Print (msg2)
MSG2 = "haha{0}, dddd{1}"
Print (msg2.format (' Alex ', 33))
7) Center Center
Name= "alex li"
Print (name.center (40, '-'))
8) Find Lookup
name = ' ALEX3SDF '
Print (name.find (' a '))
9) whether the isdigit is a digital
Age = Input ("your Age:")
If Age.isdigit ():
age = int (age)
Print (age)
Else
Print ("invalid Data Type")
Isalnum If only alphanumeric characters are included
name = ' ALEX3SDF '
Print (name.isalnum ())
One) EndsWith when does the end
name = ' ALEX3SDF '
Print (name.endswith (' DF '))
StartsWith when does it start?
name = ' ALEX3SDF '
Print (name.startswith (' DF '))
Upper Caps
name = ' ALEX3SDF '
Print (name.upper ())
) Lower lowercase
name = ' ALEX3SDF '
Print (name.upper (). Lower ())
Len length
Print (len (name))
4. List
Lists are called in Python only, and are called arrays in other Languages.
To create a list:
Name_list = [' Alex ', ' seven ', ' Eric ']
Or
name_list = list ([' Alex ', ' seven ', ' Eric ')
Basic Operation:
Index
Slice
Additional
Delete
Length
Cycle
Contains
Name = [' Alex ', ' Jack ', ' Rain ', ' Eric ', ' Monica ', ' Fiona ']
>>> name[:]
[' Alex ', ' Jack ', ' Rain ', ' Eric ', ' Monica ', ' Fiona ']
Index
>>> name[2]
' Rain '
Slice
>>> name[2:4]
[' Rain ', ' Eric ']
>>> name[2:4][0]
' Rain '
>>> name[2:4][0][1:2]
A
Modify:
>>> name[1]= "xiaoming"
>>> Name
[' Alex ', ' xiaoming ', ' Rain ', ' Eric ', ' Monica ', ' Fiona ']
Insert:
>>> name.insert (2, ' daming ')
>>> Name
[' Alex ', ' xiaoming ', ' daming ', ' Rain ', ' Eric ', ' Monica ', ' Fiona ']
Additional:
>>> name.append (' Alex ')
>>> Name
[' Alex ', ' xiaoming ', ' daming ', ' Rain ', ' Eric ', ' Monica ', ' Fiona ', ' Alex ']
Delete:
>>> Name.remove ("daming")
>>> Name
[' Alex ', ' xiaoming ', ' Rain ', ' Eric ', ' Monica ', ' Fiona ', ' Alex ']
Practice:
Insert the name of two pro group members into the middle
List of people taking out 第3-8
Delete a 9th person
Delete the 2 other groups that you just joined, one at a time.
Add the Leader's name to the group Leader's notes
Ask you to print a person every other person
>>> name = [' Alex ', ' xiaoming ', ' Rain ', ' Eric ', ' Monica ', ' Fiona ']
>>> Name.insert ( -1, "xiaochuan")
>>> Name.insert (5, "dachuan")
>>> name[3:8]
[' Eric ', ' Monica ', ' Dachuan ', ' Xiaochuan ', ' Fiona ']
>>> Name.remove ("Fiona")
>>> Name
[' Alex ', ' xiaoming ', ' Rain ', ' Eric ', ' Monica ', ' Dachuan ', ' Fiona ']
>>> del name[4:6]
>>> Print (name[::2])
Length:
>>> Len (name)
7
>>> Name
[' Alex ', ' xiaoming ', ' Rain ', ' Eric ', ' Monica ', ' Fiona ', ' Alex ']
5, tuples (immutable List)
To create a tuple:
ages = (11, 22, 33, 44, 55)
Or
ages = tuple ((11, 22, 33, 44, 55))
6. Dictionary (unordered)
To create a dictionary:
person = {"name": "mr.wu", ' Age ': 18}
Or
person = dict ({"name": "mr.wu", ' age ': 18})
Common Operations:
Index
New
Delete
key, value, Key-value Pairs
Cycle
Length
third, Data operation
The smallest unit that can be represented in a computer is a bits.
The smallest unit that can be stored in a computer is a bits (bit).
8bit = byte (bytes)
1024byte = 1kbyte
1024kbyte = 1mbyte
1024MB = 1GB
1024GB = 1T
Arithmetic operations:
Comparison Operation:
Assignment operation:
Logical operation:
Member Operations:
Identity operation:
Bit operations:
This article is from the "curves" blog, so be sure to keep this source http://luchuangao.blog.51cto.com/11311715/1852009
Python road, Python basics 2 (second week)