long_string1 = ''' Creating long string in Python, method1 like this... ''' print(long_string1) long_string2 = ('\n' 'Creating long string in Python,\n' 'method2 like this...\n') print(long_string2)
##global variable here ## myvar = 'test1' def my_func1(): ##it will print the content of global variable ## print( myvar ) my_func1() def my_func2(): myvar = ' test2 ' ##it will print the content of local variable ## print( myvar ) my_func2() ##the content of global variable does not change ## print( myvar ) def my_func3(): ##use global variable in function like this ## global myvar myvar = ' test3' print( myvar ) my_func3() ##the content of global variable will be changed in the function ## print( myvar )
##import## import tempfile ##generate temporary file and write ## with tempfile.NamedTemporaryFile( suffix='.txt', prefix='tmp', dir='d:\\cykuo\\tmp' , delete=False) as f: print(f.name) f.write( b 'test data') #若沒有加 b , 會出現 Excption: # TypeError: a bytes-like object is required, not 'str'