Coursera课程Python for everyone:chapter6

Chapter 6 Quiz

10 试题

1. 

What does the following Python Program print out?

str1 = "Hello"
str2 = 'there'
bob = str1 + str2
print bob

Hellothere

Hello there

Hello

there

Hello

2. 

What does the following Python program print out?

x = '40'
y = int(x) + 2
print y

402

42

int402

x2

3. 

How would you use the index operator [] to print out the letter q from the following string?

x = 'From marquard@uct.ac.za'

print x[q]

print x[8]

print x[9]

print x[-1]

print x[7]

4. 

How would you use string slicing [:] to print out 'uct' from the following string?

x = 'From marquard@uct.ac.za'

print x[14:17]

print x[14:3]

print x[15:18]

print x[14+17]

print x[15:3]

print x[14/17]

5. 

What is the iteration variable in the following Python code?

for letter in 'banana' :
    print letter

print

letter

for

'banana'

in

6. 

What does the following Python code print out?

print len('banana')*7

bananabananabananabananabananabananabanana

42

banana7

0

7. 

How would you print out the following variable in all upper case in Python?

greet = 'Hello Bob'

console.log(greet.toUpperCase());

print uc($greet);

print greet.upper()

puts greet.ucase;
8. 

Which of the following is not a valid string method in Python?

boldface()

upper()

lower()

lstrip()

startswith()

9. 

What will the following Python code print out?

data = 'From stephen.marquard@uct.ac.za Sat Jan  5 09:14:16 2008'
pos = data.find('.')
print data[pos:pos+3]

mar

uct

Sat

.ma

10. 

Which of the following string methods removes whitespace from both the beginning and end of a string?

strip()

split()

wsrem()

strtrunc()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值