python答题0311

  1. What is CJKV?
CJKV Information Processing
Ken Lunde
O'Reilly
2009
912 pages

Excellent reference for CJKV issues such as
Unicode GB2312, GBK, GB18030 etc.
  1. Who is Guido van Rossum?
Guido van Rossum, 1980s
吉多·范·罗苏姆 (Jí duō·fàn·luō sū mǔ)

He is from Netherlands (荷兰)
  1. What does it mean for programs to be ‘portable’?
Portable - develop on Linux, use on Windows, Mac etc and so on
  1. What are the two versions of Python?
Python 2.x (usually 2.7)
The traditional form
Stayed the same for many years
Had a few problems
Python 3.x
The newer form
Similar to 2.x but some differences
  1. What character encoding should be used for Python programs?
UTF-8 Encoding
  1. What is a comment? What are the two types of comment in Python?
A comment is something which is ignored

Use comments to add notes to explain
how the program works

First form starts with #
Second form is multiple lines

Starts and ends with """ or '''

Here is the """ form
(three double quotes ")
Second form cont.

Here is the ''' form
(three single quotes ')
  1. What is the syntax of a Python variable name?
A variable name:
Can contain letters a-z
Can contain letters A-Z
Can contain digits 0-9
Can contain underscores _
However:
Cannot start with a digit
Cannot contain any other types of letter
e.g.%,^’ etc cannot be used in
variable names

Some people use ‘Camel Case’ to show words in a long variable name:
thisIsAVariableName
Other people use underscores instead:
this_is_a_variable_name
Python allows both forms.
  1. What is Camel Case?
  2. What is the difference between a declaration (e.g. x = 1) and an assignment (e.g. x = 1 )?
a declaration (e.g. x = 1) decalre variable x and assign a value
an assignment (e.g. x = 1 ) x already exist, change its value
  1. What is the difference between / and // ?
/ division 
// Integer division	Rounds down to nearest whole number
x = 5; y = 2;
x/y
2.5
x//y
2
  1. What is the difference between // and %?
% Modulus模运算符 Remainder after integer division
x = 5; y = 2;
x//y
2
x%y
1
  1. What does x ** 2 mean?
** Exponent 指数算子
x的二次方
The second power of x
  1. What does x += 1 mean?
Combine Operator with Assignment 赋值与运算的结合
x = x + 1
A shorter method is available:

x += 1

1. Get value of x
2. Add one to it
3. Assign new value to x

Similarly with *=, -=, /=
Also works with //, %, **
  1. What is the largest integer in Python?
263次方-1
  1. What is the longest string in Python?
A Python string is allowed to be very long
You can use \ to continue onto the next line
You can read a whole file into a string  if you wish.
  1. In something like:
    university = “Northwest” + “University” +
    “1902”
‘NorthwestUniversity 1902
  1. What is the purpose of the backslash \ ?
We can join any number of strings

Note the use of \ to continue the line

Without \, we get an error
  1. What does this do: ‘exchange rate is %3.1f’ % (9.09)
'exchange rate is 9.1'
  1. What is the difference between “1902” and 1902 ?
1902” is a string
1902 is an integer
  1. What is type casting in Python? Give an example using the str() function
s1 = "Northwest was founded in "
s2 = s1 + str(1902)
s2
'Northwest was founded in 1902'
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值