python (third day)

First, the input from the keyboard

For access to information from the keyboard in c and c ++, we have strange, then python is how to do it, and that is through the function input (), described below under input () features

input()

(1) input by the user gave his characters accept spaces are also exceptions, unless you enter a carriage return, it would not end.

Information (2) to get a string type, even if the figure is, they can not participate in operations between, can only be achieved through conversion.

(3) brackets may be added to prompt the user to enter information in favor

Two, while circulation

while conditions:

  ...

Third, function

def function name ():

  ...

Precautions:

(1) If you need to pass parameters inside the parentheses, then do not write type

(2) the position of the argument: The transfer position is a position in the order to correspond example:
DEF Fun (A, B):

    ...

fun(c,d)

This time corresponds to c a, d b corresponding to

 

(3) the keyword parameter

def fun(a,b):

  ...

fun(a='hello',b='world')

(4) Default

def fun(a,b='dog')

  ...

 

fun('hello')

When fun () return only one parameter, the default position in accordance with the parameter, b output in accordance with the default value, if the pass when two parameters, the default value b will be transferred past parameters covered.

 

Guess you like

Origin www.cnblogs.com/liwen0329/p/11184416.html