Operations for Python data types

Source: Internet
Author: User
Tags mathematical constants mathematical functions shallow copy square root python list

First, numbers (number)

1. Mathematical Functions:

function return value (description)
ABS (x) Returns the absolute value of a number, such as ABS (-10) returns 10
Ceil (x) Returns the top integer of a number, such as Math.ceil (4.1) returns 5

CMP (x, y)

If x < y returns 1, if x = = y returns 0, if x > y returns 1. Python 3 is deprecated . Replace with use (x>y)-(x<y) .
EXP (x) Returns the x power of E (ex), such as MATH.EXP (1) returns 2.718281828459045
Fabs (x) Returns the absolute value of a number, such as Math.fabs (-10) returns 10.0
Floor (x) Returns the lower integer of a number, such as Math.floor (4.9) returns 4
Log (x) If Math.log (MATH.E) returns 1.0,math.log (100,10) returns 2.0
LOG10 (x) Returns the logarithm of x with a base of 10, such as MATH.LOG10 (100) returns 2.0
Max (x1, x2,...) Returns the maximum value of a given parameter, which can be a sequence.
Min (x1, x2,...) Returns the minimum value for a given parameter, which can be a sequence.
MODF (x) Returns the integer portion of x and the fractional part, the two-part numeric symbol is the same as x, and the integer part is represented by a floating-point type.
Pow (x, y) The value after the x**y operation.
Round (x [, N]) Returns the rounded value of the floating-point number x, if given an n value, that represents the digits rounded to the decimal point.
sqrt (x) Returns the square root of the number x, the number can be negative, and the return type is real, such as MATH.SQRT (4) returns 2+0J

2. Random number function:

function Description
Choice (seq) Pick an element randomly from the elements of the sequence, such as Random.choice (range (10)), and randomly pick an integer from 0 to 9.
Randrange ([Start,] stop [, step]) Gets a random number in the collection that increments by the specified cardinality from the specified range, and the base default value is 1
Random () Randomly generates the next real number, which is within the [0,1] range.
Seed ([x]) Changes the seeding seed of the random number generator. If you don't know how it works, you don't have to specifically set Seed,python to help you choose Seed.
Shuffle (LST) Randomly sort all elements of a sequence
Uniform (x, Y) Randomly generates the next real number, which is within the [x, Y] range.

3. Trigonometric functions:

functions description
ACOs (x) returns the inverse cosine radian value of x.
ASIN (x) returns the arc value of the sine of X.  
atan (x) returns the arc tangent value of x.
atan2 (y, x) returns the inverse tangent value of the given x and Y coordinate values.
cos (x) Returns the cosine of the arc of X.
hypot (x, y) returns the Euclidean norm sqrt (x*x + y*y).
sin (x) returns the sinusoidal value of the X-radians.
Tan (x) Returns the tangent of x radians.
degrees (x) converts radians to angles, such as degrees (MATH.PI/2), returns 90.0
radians (x) converts an angle to radians
 

4. Mathematical constants:

Constants Description
Pi Mathematical constant Pi (pi, usually denoted by π)
E Mathematical constants E,e i.e. natural constants (natural constants)

Second, string

1.Python string built-in function:

Serial Number Method and Description
1

Capitalize ()
Converts the first character of a string to uppercase

2

Center (width, Fillchar)

Returns a string that specifies the width of the center, Fillchar is a filled character, and the default is a space.
3

Count (str, beg= 0,end=len (String))

Returns the number of occurrences of STR in a string, if beg or end specifies that the number of STR occurrences in the specified range is returned
4

Bytes.decode (encoding= "Utf-8", errors= "strict")

There is no Decode method in Python3, but we can use the decode () method of the Bytes object to decode the given bytes object, which can be encoded back by bytes ().
5

Encode (encoding= ' UTF-8 ', errors= ' strict ')

Encodes a string in the encoded format specified by encoding, if an error defaults to a ValueError exception unless errors specifies ' ignore ' or ' replace '
6

EndsWith (suffix, beg=0, End=len (String))
Checks whether the string ends with obj, or returns False if beg or end specifies whether to end with obj in the specified range, or True if it is.

7

Expandtabs (tabsize=8)

Turns the tab symbol in string strings to a space, and the default number of spaces for the tab symbol is 8.
8

Find (str, beg=0 End=len (String))

Detects if STR is contained in a string, if beg and end specify a range, the check is contained within the specified range, or returns 1 if the index value is returned.
9

Index (str, beg=0, End=len (String))

Just like the Find () method, only if STR does not report an exception in the string.
10

Isalnum ()

Returns True if the string has at least one character and all characters are letters or numbers, otherwise False
11

Isalpha ()

Returns True if the string has at least one character and all characters are letters, otherwise False
12

IsDigit ()

Returns True if the string contains only a number, otherwise False:
13

Islower ()

Returns True if the string contains at least one case-sensitive character, and all of these (case-sensitive) characters are lowercase, otherwise False
14

IsNumeric ()

Returns True if the string contains only numeric characters, otherwise False
15

Isspace ()

Returns True if the string contains only spaces, otherwise False is returned.
16

Istitle ()

Returns True if the string is heading (see Title ()), otherwise False
17

Isupper ()

Returns True if the string contains at least one case-sensitive character, and all of these (case-sensitive) characters are uppercase, otherwise False
18

Join (SEQ)

Merges all elements of the SEQ (the string representation) into a new string with the specified string as a delimiter
19

Len (String)

return string length
20

Ljust (width[, Fillchar])

Returns a string that is left-justified by using Fillchar to fill a new string of length width, and fillchar the default is a space.
21st

Lower ()

Converts all uppercase characters in a string to lowercase.
22

Lstrip ()

Truncate the space to the left of the string
23

Maketrans ()

To create a conversion table of character mappings, for the simplest invocation of two parameters, the first argument is a string representing the character that needs to be converted, and the second argument is the target of the string representation of the transformation.
24

Max (str)

Returns the largest letter in the string str.
25

Min (str)

Returns the smallest letter in the string str.
26

Replace (old, new [, Max])

Replace the str1 in the string with str2, and if Max specifies it, the replacement does not exceed Max times.
27

RFind (str, Beg=0,end=len (String))

Similar to the Find () function, it is just looking from the right.
28

Rindex (str, beg=0, End=len (String))

Similar to index (), but starting from the right.
29

Rjust (width,[, Fillchar])

Returns the right alignment of an original string and fills a new string of length width with Fillchar (default space)
30

Rstrip ()

Removes a space at the end of a string string.
31

Split (str= "", Num=string.count (str))

Num=string.count (str)) intercepts a string with the Str delimiter, and only the NUM substring if NUM has a specified value
32

Splitlines ([keepends])

Separated by rows (' \ r ', ' \ r \ n ', \ n '), returns a list containing the rows as elements, if the argument keepends is False, does not contain a newline character, and if true, the newline character is preserved.
33

StartsWith (str, Beg=0,end=len (String))

Checks whether the string starts with obj, returns True, or False. If beg and end specify a value, the check is within the specified range.
34

Strip ([chars])

Execute Lstrip () and Rstrip () on a string
35

Swapcase ()

Convert uppercase in a string to lowercase, lowercase to uppercase
36

Title ()

Returns the "heading" string, meaning all words start with uppercase and the remaining letters are lowercase (see istitle ())
37

Translate (table, deletechars= "")

Converts a string character to a table (containing 256 characters) given by STR, and the character to be filtered out into the Deletechars parameter
38

Upper ()

lowercase letters in a converted string are capitalized
39

Zfill (width)

Returns a string of length width, the original string right-aligned, front padding 0
40

Isdecimal ()

Checks whether the string contains only decimal characters and returns False if true.

Third, list

1.Python List functions:

Serial Number function
1 Len (list)
Number of list elements
2 Max (list)
Returns the maximum value of a list element
3 MIN (list)
Returns the minimum value of a list element
4 List (seq)
Convert a tuple to a list

2.Python List Method:

Td>10
ordinal method
1 List.append (obj)
Add a new object at the end of the list
2 list.count (obj)
count the number of occurrences of an element in the list
3 list.extend (seq)
Append multiple values from another sequence at the end of the list (extend the original list with a new list)
4 list.index (obj)
to find the index position of the first occurrence of a value from a list
5 list.insert (index, obj) inserting an object into the list
6 list.pop (obj=list[-1])
removes an element from the list (the last element by default) and returns the value of the element
7 list.remove (obj)
Remove the first occurrence of a value in a list
8 LIST.R Everse ()
Elements in reverse list
9 list.sort ([func])
Sort the original list
list.clear ()
Empty list
one list.copy ()
Copy list

Four, the dictionary

1. dictionary built-in functions:

Serial Number Functions and descriptions Example
1 Len (dict)
Calculates the number of dictionary elements, that is, the total number of keys.
>>>={' Name ':' Runoob ',' age ':7,' Class ':' First '}>>> len(dict)3       
2 STR (DICT)
The output dictionary, expressed as a printable string.
>>>={' Name ':' Runoob ',' age ':7,' Class ':' First '}>>> str(dict)"{' Name ': ' Runoob ', ' Class ': ' First ', ' Age ': 7}" 
3 Type (variable)
Returns the type of the variable entered and returns the dictionary type if the variable is a dictionary.
>>> dict = {' Name ': ' Runoob ', ' age ': 7 , ' Class ': ' first '}>>> type(dict)< class ' Dict '>              

2. Dictionary built-in methods:

Serial Number Functions and descriptions
1 Radiansdict.clear ()
Delete all elements in a dictionary
2 Radiansdict.copy ()
Returns a shallow copy of a dictionary
3 Radiansdict.fromkeys ()
Create a new dictionary with the keys to the dictionary in sequence seq, Val is the initial value corresponding to all keys in the dictionary
4 Radiansdict.get (Key, Default=none)
Returns the value of the specified key if the value does not return the default value in the dictionary
5 Key in Dict
Returns False if the key returns true in the dictionary Dict
6 Radiansdict.items ()
Returns an array of traversed (key, value) tuples as a list
7 Radiansdict.keys ()
Returns a dictionary of all keys in a list
8 Radiansdict.setdefault (Key, Default=none)
Similar to get (), but if the key does not exist in the dictionary, the key is added and the value is set to default
9 Radiansdict.update (DICT2)
Update the key/value pairs of the dictionary dict2 to the Dict
10 Radiansdict.values ()
Returns all values in the dictionary as a list
11 Pop (Key[,default])
Deletes the value of the dictionary given key key, and returns the value to be deleted. The key value must be given. Otherwise, the default value is returned.
12 Popitem ()
Randomly returns and deletes a pair of keys and values in the dictionary.

Operations for Python data types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.