Python基础

1.print输出

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

注意点:
1.sep分隔符,将输入的多个值在打印的时候分开
2.endend默认是'\n',表示换行,可以修改
3.*args表示的是我们需要打印出来的字符串(或者其他内容),在函数调用的过程中,以","隔开,将所有位置的参数打包成元组

2.input输入

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
    注意点:
    1.input返回的一定是一个字符串
    2.input获取的是标准输入
    3.input会阻塞进程,等待键盘输入,这条语句之后的代码不再执行

3.字符串

3.1字符串拼接

3.1.1 +号


3.1.2 format

def format(self, *args, **kwargs): # known special case of str.format
    """
    S.format(*args, **kwargs) -> str
    
    Return a formatted version of S, using substitutions from args and kwargs.
    The substitutions are identified by braces ('{' and '}').
    """
    pass
    注意点:
    1.format是str类自带的方法
    2.配合{}使用,{}定义了需要使用的位置
    3.多个数值填充的时候,填充数值要遵从顺序
    4.多个数值进行填充的时候,如果format中填充的数据没有按照顺序传递,{}中可以定义使用的参数位置,位置从0开始
    5.多个值在进行填充的时候,如果format实参是键值结构传递的,我们可以在{}中填充参数的名字

实例:

#str1 = 'my name is {username} ,my age is {age}'.format(age=age,username=username

3.1.3 %s占位符

str1 = 'my name is %s ,my age is %s'%(username,age)

str1 = 'my name is %s ,my age is %d'%(username,int(age))

注意点:

3.1.4 结构占位(补充内容)

def new():
    pass

注意点:
1.用来补充类,函数等结构

3.2 字符串开头结尾的判断

3.2.1 startswith

def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
    """
    S.startswith(prefix[, start[, end]]) -> bool
    
    Return True if S starts with the specified prefix, False otherwise.
    With optional start, test S beginning at that position.
    With optional end, stop comparing S at that position.
    prefix can also be a tuple of strings to try.
    """
    return False
    
    
注意点:
1.必须传递指定的字符串,用来判断以。。。开头
2.start,end存在指定的默认参数,默认是None,代表的是从字符串开始的位置到结束的位置
3.如果start和end指定,则按照指定的位置来进行判断
4.指定判断的字符串可以是单个字符串,也可以是多个字符串元组

3.2.2 endswith

def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
    """
    S.endswith(suffix[, start[, end]]) -> bool
    
    Return True if S ends with the specified suffix, False otherwise.
    With optional start, test S beginning at that position.
    With optional end, stop comparing S at that position.
    suffix can also be a tuple of strings to try.
    """
    return False

3.3 查找指定的内容

3.3.1 find

def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
    """
    S.find(sub[, start[, end]]) -> int
    
    Return the lowest index in S where substring sub is found,
    such that sub is contained within S[start:end].  Optional
    arguments start and end are interpreted as in slice notation.
    
    Return -1 on failure.
    """
    return 0
    
    
注意点:
1.sub目标字符串需要传递
2.start,end控制查找范围
3.如果目标字符串在当前字符串中不存在,则返回-1
4.返回的是目标字符串所在位置的最低索引

3.3.2 rfind

def rfind(self, 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值