Python Foundation fourth day

Source: Internet
Author: User

Built-in functions: ABS () for absolute use: deal with left and right problems, coordinates,

Max () max (12,13,14) ——— min () min () min (9,8,7)---->7

POW () 5,3----->5 three round () rounding round (3.6)---->4 round (4.5)--->4 comment (bug): If 4.5,6.5,8.5 .... (The integer part), the odd number can be entered, the even number cannot enter

SUM () sum--------sum ([1, 2, 3])

Module : (Package, namespace) when you need to import the-------"Imports module name Why use : In more than one PY file will appear the same name (variables, functions, classes) in order not to let the name conflict the different py files in different folders Math.ceil (3.9) #向上取整Math.floor (3.9) #向下取整 math.sqrt (+) #平方根 math.modf (3.14) #返回小数和整数部分 Math.PI #- ----"3.141592653589793

Random number module : Random

Random.random ()---> #随机0-1 digit (decimal) less than 1
Random.randint (1, 3)----#随机1-3 integer can be taken to the maximum value
Random.randrange (1, 3)----#随机1-3 integer, without maximum value
Random.randrange (2)----#只写一个默认从0开始到这个数字, maximum value not being taken
Random.randrange (1,10,2)----"#2是步长
Random.uniform (1, 3)----"#随机1-3 decimals
Random.choice (["A", "B", 1, 2])-----"#随机列表中的一个数据
Random.sample (["A", "B", 1, 2], 2)-----"#随机列表中指定的几个数据

li=[1,2,3,4,5]--"random.shuffle (LI)---"# to scramble the data in the list
Random.choice ("abcd1234")----"#从字符串中随机取一个字符

Python Foundation fourth day

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.