1 / 3

s1=“hello” s1( 请计算表达式 ) print s1( 语句,显示表达式的结果 ) type(‘hello’) id(“hello”) id(s1) s2=s1 id(s2)

演示. 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]

jera
Download Presentation

s1=“hello” s1( 请计算表达式 ) print s1( 语句,显示表达式的结果 ) type(‘hello’) id(“hello”) id(s1) s2=s1 id(s2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 演示 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)

  2. 演示 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)

  3. x=open(‘c:\user\dxj\infileName.txt’, ‘r’) x.read() x.readline() x.readline() x.readlines() x.close() x.read()

More Related