Python Exercises(1)

本文围绕Python展开,解答了多个基础问题。包括运算顺序,编辑器颜色获取方法,代码中#不被忽略的原因,=和==的区别,变量命名规则,浮点数四舍五入方法等,为Python初学者提供了实用的知识。

1、

                                                  

(1)The order of operations :First, do the multiplication and division from left to right; Then, do the addition and subtraction from left to right.

 

2、

                                                          

(1)How do I get colors in my editor?(Save our file first as a .py file, such as ex1.py. Then we'll have color when we type.)

 

3、

                      

(1)Why does the # in print("Hi # there.") not get ignored?(The # in that code is inside a string, so it will be put into the string until the ending " character is hit. So the # here is just considered as characters, not comments.)

 

4、

                  

(1)What's the difference between = and ==?(The =(single-equal) assigns the value on the right to a variable on the left.

The ==(double-equal) tests whether two things have the same value.)

(2)Can we write x=100 instead of x = 100?(Of course we can, but it's a bad form. We'd better add space around operators like this so that it's easier to read.)

 

5、

          (1)Can I make a variable like this: 1 = 'Zed Shaw' ?(No, 1 is not a valid variable name. They need to start with a character, so a1 would work.)

(2)How can I round a floating point number?(You can use the round() function like this: round(1.7333).)(四舍五入)

 

6、

       

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值