Python复习笔记01

字符串是不可变的:

指的是当修改字符串时,无法直接修改内存数据,而是重新建立新的内存,并修改变量的指针指向新的内存。

与C不同:

与 C 字符串不同的是,Python 字符串不能被改变。向一个索引位置赋值,比如 word[0] = 'm' 会导致错误。

Python 允许处理 unicode 字符串:

1.什么是 unicode 字符串:

Unicode(统一码、万国码、单一码)是计算机科学领域里的一项业界标准,包括字符集、编码方案等。Unicode 是为了解决传统的字符编码方案的局限而产生的,它为每种语言中的每个字符设定了统一并且唯一的二进制编码,以满足跨语言、跨平台进行文本转换、处理的要求。

也就是说,Unicode将每种语言的每一个文字都编为了一串数字码,即每一个字符都有一个Unicode与之对应。

2.Python允许使用unicode编码并输出

空行

空行不是python语法的一部分,但是程序代码的一部分,它的作用为:
分隔两段不同功能或含义的代码,便于日后代码的维护或重构。


#hello world
print("hello world")
hello world
#string

print("this ""is ""string""\\\\n")

print("this is a line with a \\\\n")
print(r"this is a line with a \\\\n" "\\\\n" )
print(R"this is a line with a \\\\n" r"\\\\n" )
this is string

this is a line with a 

this is a line with a \\\\n

this is a line with a \\\\n\\\\n
#string
str = u"this is an unicode string"
print(str)

str = u"你好"
print(str)
uni = str.encode('unicode-escape').decode()
print(uni)
this is an unicode string
你好
\\\\u4f60\\\\u597d
#string
print('\\\\u4f60\\\\u597d')
你好
#string
str="123456789"
print(str[0:3])      #第一个到第三个字符
123
#string
print(str[0:5:1])    #第1个到第5个字符,步长为1,每两个元素之间隔0个
print(str[0:5:2])    #第1个到第5个字符,步长为2,每两个元素之间隔1个
print(str[0:5:3])    #第1个到第5个字符,步长为3,每两个元素之间隔2个
12345
135
14
str = input("\\\\nplease input a string\\\\n")
print(str)
please input a string
string
string
x=1;y=2           #同行多条语句
print(x)          #换行输出
print(y)
print(x,end='-')  #不换行输出
print(y,end='')
1
2
1-2
import sys
print('================Python import mode==========================')
print ('命令行参数为:')
for i in sys.argv:
    print (i)
================Python import mode==========================
命令行参数为:
E:\\\\Anaconda3\\\\lib\\\\site-packages\\\\ipykernel_launcher.py
-f
C:\\\\Users\\\\24492\\\\AppData\\\\Roaming\\\\jupyter\\\\runtime\\\\kernel-a4851340-47aa-4202-a9b8-eabec0341e24.json
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_43335313

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值