Python format string formatting, mathematical meaning functions and functions in Python day14

Source: Internet
Author: User
Tags function definition

Format string formatted, must be one by one corresponding

' I am {}, age{},{} '. Format ('seven',',') print (TPL)
' I am {1}, age{2},{2} '. Format ('seven',',') print (TPL)

Take a tuple first

TPL = ' I am {0[0]} ', Format ([1,2,3],[123])

function definition methods in Python:

def Test (x):     ' The function Definitions ' #注释函数    x+ =1    return X

def: A keyword that defines a function

Test: Name of function

(): Internal Medicine defined formal parameters

' Document description, not necessary, strongly recommended to add

X+=1: Generic code block or program processing logic

Return: Define the return value

Using functions

def Test (x):     ' :p Aram X: Shaping numbers ' #注释函数    y=2*x+1    return  = Test (3) print (a)

No return value, none returned

There is only one return value, which returns the value

Returns a tuple with multiple return values

Parameters of the function

parameters, which are useful only if the function is called

arguments, always present

Formal parameter, argument one by one corresponds

def text (x, y):    res=x*y    return= text (1,2) print ( Z)

Parameter Group * * Dictionary * list

def text (x,*y):    print (x)    print (y) c= text (1,2,3,4, 5)

Python format string formatting, mathematical meaning functions and functions in Python day14

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.