Python基础:注释、输入输出函数和字符串的基本操作

1. 注释

1.1 单行注释

# 这是语句
pycharm的快捷键: Ctrl + /

1.2 多行注释

‘’’

这是语句

‘’’

“”"
这是语句
“”"

2. 输出函数

def print(self, *args, sep=' ', end='\n', file=None): # known special case of print
    """
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
    
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.
    """
    pass

3. 输入函数

def input(*args, **kwargs): # real signature unknown
    """
    Read a string from standard input.  The trailing newline is stripped.
    
    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.
    
    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.
    """
    pass

4. 字符串

4.1 字符串的格式

str = 'abcdefghjkl'

4.2 字符串的操作

# 查看类型
print(type(str))
# 获取下标
print(str.index('c'))
# 逆置
print(str[::-1])
# 切片
print(str[0:3])  # 左闭右开
print(str[-3:])

# 注:str[起始位置:结束位置:步长]
# 步长为正数,代表从开始向结束取值
# 步长为负数,代表从末尾向前取值
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值