Sike basis of python string

Let's look at what is the string:
Most programs define and collect some data, and then use them to do meaningful things. In view of this, the data classification of great benefit. The first type of data that we will introduce a string. Although seemingly simple string, but they can be used in many different ways. String is a series of characters. In Python, with all the string enclosed in quotes, which quotes can be single quotes, double quotes can also be
---- Transfer "python programming from entry to practice"
above explanation, in my opinion is relatively easy to understand of the, if you want in-depth understanding of the string we will look at the various bar coding standards, such as 'utf-8', 'ANSI ', 'ASCII', anyway, I saw a large head, I want to go see it self-flagellation . I am a big head.

str1='abdccds'这是字符串
str2="abcdssja"这也是字符串
str3='abc 234 FFFF@@'这也是字符串
字符串都有哪些方法呢:
一条命令搞定
print(dir(str))
结果
['__add__', '__class__','__contains__','__delattr__',
 '__dir__','__doc__','__eq__','__format__','__ge__',
 '__getattribute__','__getitem__','__getnewargs__',
 '__gt__','__hash__','__init__', '__init_subclass__',
 '__iter__', '__le__','__len__', '__lt__', '__mod__', '__mul__', '__ne__','__new__','__reduce__','__reduce_ex__',
 '__repr__','__rmod__', '__rmul__','__setattr__' '__sizeof__',
 '__str__', '__subclasshook__','capitalize','casefold',
 'center','count','encode','endswith', 'expandtabs',
 'find','format', 'format_map', 'index', 'isalnum',
 'isalpha', 'isascii', 'isdecimal', 'isdigit',
 'isidentifier', 'islower', 'isnumeric', 'isprintable',
 'isspace', 'istitle', 'isupper', 'join', 'ljust',
 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit',
 'rstrip', 'split', 'splitlines', 'startswith', 'strip',
 'swapcase', 'title', 'translate', 'upper', 'zfill']

Good fun, actually there are so many string methods,
** What is the way to do that, he is to be able to do something, it function, a function that I can do something for him. ** finally say a kind of point like a fun learning outcomes ah! ! !
We come together to press a play about! ! !

首先前面__和后面有__的方法我们不要去纠结他,
现在我们层次还很low,还不适合去追求他们。
我们要把注意力放在下面这些方法上。
'capitalize','casefold','center','count','encode',
'endswith', 'expandtabs', 'find','format', 
'format_map', 'index', 'isalnum','isalpha', 
'isascii', 'isdecimal', 'isdigit','isidentifier', 
'islower', 'isnumeric', 'isprintable','isspace', 
'istitle', 'isupper', 'join', 'ljust', 'lower', 
'lstrip', 'maketrans', 'partition', 'replace', 
'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit',
 'rstrip', 'split', 'splitlines', 'startswith', 'strip',
 'swapcase', 'title', 'translate', 'upper', 'zfill'

How we use the string method it?
"String." Method name (parameter) == "" " 'hahah'.upper ( ) is one such.
This method has a string write what use is it?

很简单一个函数搞定
help(str.upper)
输出结果:
---------------------------------------------------
Help on method_descriptor:
upper(self, /)
    Return a copy of the string converted to uppercase.
--------------------------------------------------------
    **返回转换为大写的字符串的副本。(转自百度翻译)**
    
    我们来试一试这个方法:
    'abddddAAAA123'.upper()
    返回的结果:'ABDDDDAAAA123'
    字符串完全变成了大写,
    这就是这个方法做的,不需要任何参数。
    自学一定要多看文档,顺便学下英文。

We can console, use the help function again look at the role and use of other methods, such as title (), for example capitalize (), as well as casefold ().
Today, we first come here, or to be more hands-on, ground brains, we still need more hands frequently ventilated.

Published 23 original articles · won praise 5 · Views 382

Guess you like

Origin blog.csdn.net/weixin_43287121/article/details/104505297