python基础(一)

最近开始自学python,整理学习过程的记录。

1.交互

print("hello")

2.数和表达式

1/2          0.5  #浮点
1/1          1.0
1//2         0    #整除
1//1         1
5.0//2.4     2.0  #表达式里只要有浮点数,除和整除,都是浮点数

2**2    4
-2**2    -4
(-2)**2   4

pow(2,3)        8
abs(-10)        10
round(1.2)     1   #圆整到最近的整数

3.变量

x=3
x*2     6
'''
使用变量前必须给它赋值,因为python变量没有默认值名称(标识符)只能由字母、数字和下划线构成,且不能以数字打头
'''

#if语句
if 1 == 1: print('One equals one')

4.模块

import math  #(使用模块扩展,需要import)
math.floor(32.9)  32  #(和使用int(32.9) 强转就相同了)

foo = math.sqrt
foo(4)   2.0

5.字符串

name = input("What is your name?")
print("Hello, " + name + "!")

 "Hello, " + "world!"
'Hello, world!'
 x = "Hello, "
 y = "world!"
 x + y
'Hello, world!'

"Hello, world!"
'Hello, world!'
print("Hello, world!")
Hello, world!

要表示很长的字符串(跨越多行的字符串),可使用三引号(而不是普通引号)。

print('''This is a very long string. It continues here.
And it's not over yet. "Hello, world!"
Still here.''')

还可使用三个双引号,如""“like this”""。请注意,这让解释器能够识别表示字符串开始和结束位置的引号,因此字符串本身可包含单引号和双引号,无需使用反斜杠进行转义。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值