Python Tutorial Note 3

Source: Internet
Author: User
Tags python list

1.python Numeric functions

CMP (x, y) if x < y returns-1 if x = = y returns 0 if x > y returns 1

Max (A, b,...) Returns the maximum value of a given parameter, which can be a sequence.

Min ()

MODF (x) returns the integer part and fractional part of X, the two-part numeric symbol is the same as x, and the integer part is represented by a floating-point type. Note: The math module needs to be imported

Random number function: Need to import random module

Random.choice (range (10)), randomly selects an integer from 0 to 9.

Ramdom.randrange ([start,] stop [,step])

Random.random () returns a randomly generated real number that is within the range of [0,1].

random. seed changes the values in seed seed seed of the random number generator, Random.random () The result of the output is not the same

The Random.shuffle (list) sorts all elements of the sequence randomly.

2.python string

Transfer character

\ line end indicates continuation character

\ nthe line break

\ r Enter

formatting strings

%s

%d

%u

String built-in functions

string.join (seq) 

Str = ;= ( "a" "B" , "C" # string sequence print Strjoin ( seq
Str.  Split(str="", num=string.  Count(str))              
Str= "Line1-abcdef \nline2-abc \NLINE4-ABCD";Print Str. print Str. ( ", 1  ); 
Result: [ ' line1-abcdef ' , ' LINE2-ABC ' , ' LINE4-ABCD ' ] [ ' line1-abcdef ' ,< Span class= "PLN" > ' \nline2-abc \nline4-abcd ' ]

String.rstrip ([char]) defaults to removing spaces at the end of a string string.

3.python List

Python contains the following functions:

Serial Number function
1 CMP (List1, List2)
Compare two elements of a list
2 Len (list)
Number of list elements
3 Max (list)
Returns the maximum value of a list element
4 MIN (list)
Returns the minimum value of a list element
5 List (seq)
Convert a tuple to a list

Python contains the following methods:

Serial Number 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 a 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)
Find the index position of the first occurrence of a value from the list
5 List.insert (index, obj)
Inserting an object into a 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)
To remove the first occurrence of a value in a list
8 List.reverse ()
Reverse List of elements
9 List.sort ([func])
Sort the original list

Python Tutorial Note 3

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.