Home > Backend Development > Python Tutorial > What does str mean in python

What does str mean in python

silencement
Release: 2020-09-17 16:26:25
Original
198722 people have browsed it

The meaning of str in python: 1. Represents the string class, you can use quotation marks (' or ") to create a string, for example "str='Hello World!'"; 2. Represents str() Function, convert the object into a form suitable for human reading. The syntax is "str(object='')" and returns the string format of an object.

What does str mean in python

1. Indicates the string class

You can use quotation marks (' or ") to create a string

The method of creating a str string is as follows:

What does str mean in python

The commonly used methods of str are as follows:

What does str mean in python

Indexing and slicing of str:

What does str mean in python

When encoded with utf-8, one Chinese character is equal to three characters. When using gbk encoding, one Chinese character is equal to two characters.

2. Express the str() function

The str() function is used to convert objects into a form suitable for human reading.

Syntax:

class str(object='')
Copy after login

Parameters

  • object -- Object.

Return value: Returns the string format of an object.

The following shows an example of using the str() method:

>>>s = 'RUNOOB'
>>> str(s)
'RUNOOB'
>>> dict = {'runoob': 'runoob.com', 'google': 'google.com'};
>>> str(dict)
"{'google': 'google.com', 'runoob': 'runoob.com'}"
>>>
Copy after login

The above is the detailed content of What does str mean in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
str
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template