Python 复习 Part2
I. String
1.definition:a sequence of case sensitive(大小写敏感) characters
2.Enclose in quotation marks or single quotes
3.Concatenate(附加)
a="hello"
b="world"
c=a+" "+b
repeat
d=a*3
#variable value
#d "hellohellohello"
4.len()is a function used to retrieve the length of a string in the parentheses
5.indexing(下标)

6.slice(切片)strings using [start:stop:step]
Get characters at start,up to and including stop-1,taking every step characters
If give two numbers,[start:stop], step=1 by default
If give one number, you are back to indexing for the character at one location (prev slide)
(其实就是在 [start,stop) 注意是左闭右开区间中,按照步长step间隔地取字符,给了step和stop默认情况下step=1,即每个字符都取出来,不跳过。给了一个数,就会倒过来取,从-1开始)

Python 3.13.7 (tags/v3.13.7:bcee1c3, Aug 14 2025, 14:15:11) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> s="immersive programming"
>>> s[::-1]
'gnimmargorp evisremmi'
>>> s[0:len(s):-1]
''
>>> s[::1]
'immersive programming'
>>> s[::2]
'imriepormig'
>>> s[::-2]
'gimropeirmi'
>>>
7.immutable(不可变)

II. Console I/O



1.f-string(格式化字符串)

III.Branching
1.comparison operations

2.logical op on bool

3.branching

4.nested code blocks

注意缩进为4个字符或者一个制表符(按Tab)
有缩进才是代码块