Home > Backend Development > Python Tutorial > How to create a string variable in python

How to create a string variable in python

藏色散人
Release: 2019-10-26 10:56:39
Original
5247 people have browsed it

How to create a string variable in python

#How to create a string variable in python?

String is the most commonly used data type in Python. We can use quotes (' or ") to create strings.

Creating a string is as simple as assigning a value to a variable. For example:

var1 = 'Hello World!'
var2 = "Python PHP"
Copy after login

Python Access Characters The value in the string

Python does not support single character types. Single characters are also used as a string in Python.

Python accesses substrings and can use square brackets to intercept them String, the following example:

Example (Python 2.0)

#!/usr/bin/python
var1 = 'Hello World!'
var2 = "Python PHP"
 
print "var1[0]: ", var1[0]
print "var2[1:5]: ", var2[1:5]
Copy after login

Execution result of the above example:

var1[0]:  H
var2[1:5]:  ytho
Copy after login

The above is the detailed content of How to create a string variable in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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