python解答0409

8056 ワード

What do these do?
36. for x in range( 0, 4 ):
        print( x )
        if x == 1:
            continue
        print( 'Last line' )

0 Last line 1 Last line 2 Last line

37. message1 = 'Global Variable'

    def my_function():
        global message1 # This is the line which has changed
        message1 = 'Local Variable'
        print( '
Inside the function:'
) print( message1, '
'
)

Message 1は'Local Variable'になります
38. def some_function( a, b, c=1, d=2, e=3 ):
         print(a,b,c,d,e)
some_function(1,3) //1 3 1 2 3
39. def some_function( a, c=1, d=2, e=3, b ):
//SyntaxError: non-default argument follows default argument  
40. def add_numbers( *num ):
        for i in num:
            print( i )
//add_numbers(1,2,3)   1  2   3(      )
41. def print_member_age( **age ):
        for i, j in age.items():
            print( i, j )
print_member_age(bill=18,yuri=30)
//bill 18
//yuri 30

42. 1. fargs
    2. *args
    3. **kwargs

Argsは、tupleである複数の無名パラメータを表します.**kwargsはdictであるキーワードパラメータを表す.またargsとkwargsを併用する場合は、*argsパラメータ列をkwargsの前に
43. import variable_num_params          !!!!!
    add_numbers( 1, 2, 3 )

44. path Environment Variable
         
45. pythonpath Environment Variable

46. lab\myfile.txt      # what is the difference?
    c:\lab\myfile.txt
//         
47. dir /b > files.txt
// b           files.txt 
48. import os
    cwd = os.getcwd()
//      
49. import os
    os.chdir( 'c:\\project' )
change current directory