Python Learning Notes

Source: Internet
Author: User

t= "I am {},age {}, {}", Format ("Seven", "Wang")

Must one by one correspond otherwise error

Need to wear a dictionary * *

t = "I am {name},age {age}, really{name}", Format (**{"name": "Seven", "Age": 18})

Print (t)

Results: I am seven,age 18,reallyseven

Send List

t= "I am {: s},age{:d}", Format (*["Seven", 18])

Binary, octal, integer, hexadecimal, hexadecimal uppercase, displayed as a percentage (six digits after the decimal point by default)

tp1= "number:{:b},{:o},{:d},{:x},{:x},{:%}", Format (15,15,15,15,15.87623,2)

Results: number:1111,17,15,f,f,1587.621450%

Function:

The definition of functions in Python: functions are a programmatic way of logically structuring and procedural.

def test (x): #x为形参, def keyword test is a function name

Second line write comment

Write n line code behind

return x #返回一个结果

Benefits of using Functions:

1. Code Reuse

2. Maintain consistency to maintain

3. Expandable

Procedure: A function that can be understood as having no return value.

If the return value is 0, that is, no return returns none

The return value is 1: Returns an object

return value >1, return tuple cylinder template

Parameters of the function: Def calc (x, y):

Res=x**y

return res

C=calc (A, B)

The first line, X, Y, is the parameter, and only the memory unit is allocated when called, and the allocated memory unit is freed immediately at the end of the call.


Python Learning Notes

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.