30 likes | 215 Views
演示. s1=“hello” s1( 请计算表达式 ) print s1( 语句,显示表达式的结果 ) type(‘hello’) id(“hello”) id(s1) s2=s1 id(s2) print s1, s2 s1+s2 3*s1 s1*3 x = input (“enter your name: ”)( 输入需加引号,否则出错,认为变量未定义 ) y = raw_input (“enter your name: ”) greet =“hello bob” greet[0] print greet[0], greet[2], greet[4]
E N D
演示 s1=“hello” s1(请计算表达式) print s1(语句,显示表达式的结果) type(‘hello’) id(“hello”) id(s1) s2=s1 id(s2) print s1, s2 s1+s2 3*s1 s1*3 x = input (“enter your name: ”)(输入需加引号,否则出错,认为变量未定义) y = raw_input (“enter your name: ”) greet =“hello bob” greet[0] print greet[0], greet[2], greet[4] x = 8 print greet[x-2] greet[0:3] greet[5:9] greet[:5] greet[:] greet[-4] len(greet)
演示 import string s = “how are you” string.split(s) s=“12,34,56,78” string.split(s, “,”) numStr = “456” numstr+1 #会出错 eval(numstr)+1 x=3.14 y=4.5 eval(“x*y”) eval(x*y) #会出错 x=eval(raw_input(“enter a number: ”)) print x*2 str(500) “hello %s %s, you may won $%d!” %(“mr.”, “smith”, 10000) “This int, %5d, was place in a field of width 5” % (7) “This int, %10d, was place in a field of width 10” % (7) “compare %f and %0.20f” % (3.14, 3.14)
x=open(‘c:\user\dxj\infileName.txt’, ‘r’) x.read() x.readline() x.readline() x.readlines() x.close() x.read()