Python Learning 06

Source: Internet
Author: User
Tags case statement pow

Python Learning-day06

Switch/case statements in 1.python

Python does not have a switch/case statement, you can use the dictionary and function in a way to achieve switch/case effect.

As follows:

Note: from__future__ Import Division: The function is to let the results of a decimal in the display of decimals, not rounding.

2. Built-in functions

(1) function:

ABS ()---------> return absolute value

Max ()--------> Max

Min ()---------> Take minimum value

Len ()--------> take length

Divmod ()------> Take mould

Example: Divmod (5,2)

Output: (2,1)

Pow (): POW (2,3)---->2 3 powers: 8

POW (2,3,4)----->2^3%4:0 (2 of 3 power)

Callable (): Tests whether a function can be called

Isinstance (): Determine the type of an object

CMP (): Compares two strings for equality (equals returns 0, unequal returns-1)

Range (): Generates a sequence (array)

Xrange (): Same as Range () for big Data Operations (higher efficiency)

Search by Help:

(2)string function:

Str.capitalize (): Capitalize first letter

Str.replace (): Replace

Str.split (): Split string

Import string: module (not commonly used)

(3) Sequence processing function:

   

Python Learning 06

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.