python string

What is Python’s String?

A string is a series of diagrams.

  1. Behavior is a sign. For example, the English language has 26 letters.
  2. Computers do not handle characters, which work in numbers (double). Even if you can see the characters on your screen, it’s stored and managed as a combination of 0’s and 1’s.
  3. Changes in these numbers are called ‘encoding’ and the process of return should be resolved. ASCII and Unicode are some of the most popular applications used.
  4. In Python, the string is the Unicode string. Unicode has been introduced to include all the characters in the language and to produce a voicemail. You can find more about Unicode here.

Example:

var1 = 'Hello World!'
var2 = "Python Programming"

How to create a Python string?

  1. String can be created when posted in a single quotes or quotes. Even three editions can be used in Python, but generally used to represent different languages ​​and documents.
  2. Python links can be created either by word or phrase or even for three.
  3. Different types of single-person species can not contain other symptoms. Otherwise, it will be lost, because they do not know the compiler where you start and close the chain. To pass this error, the use of two quotes is preferred because it helps create a letter with just a single volume. What links to the words in the biographical terms, the use of three references is suggested. This is the same, the third statement also permits creation of many chains.

Enroll Now: Python Training in Chennai

Example:

# all of the following are equivalent
my_string = 'Hello'
print(my_string)

my_string = "Hello"
print(my_string)

my_string = '''Hello'''
print(my_string)

# triple quotes string can extend multiple lines
my_string = """Hello, welcome to
 the world of Python"""
print(my_string)

Output:

Hello
Hello
Hello
Hello, welcome to
   the world of Python

String Special Operators:

Note that the letter “Hello” and the variable B ‘Python’, then –

Enroll Now: Python Training in Bangalore

DescriptionExample
+Concatenation – Adds values on either side of the operatora + b will give HelloPython
*Repetition – Creates new strings, concatenating multiple copies of the same stringa*2 will give -HelloHello
[]Slice – Gives the character from the given indexa[1] will give e
[ : ]Range Slice – Gives the characters from the given rangea[1:4] will give ell
inMembership – Returns true if a character exists in the given stringH in a will give 1
not inMembership – Returns true if a character does not exist in the given stringM not in a will give 1
r/RRaw String – Suppresses actual meaning of Escape characters. The syntax for raw strings is exactly the same as for normal strings with the exception of the raw string operator, the letter “r,” which precedes the quotation marks. The “r” can be lowercase (r) or uppercase (R) and must be placed immediately preceding the first quote mark.print r’\n’ prints \n and print R’\n’prints \n
%Format – Performs String formattingSee at next section

 

String Literals:

Python’s acronyms contain only single words or quotes.

"Hello" is like "hello".

Chains can be sent to the screen using print jobs. For example: print (“hello”).
As well as many other popular languages, Python’s string is a byte array that represents a global code character. However, Python does not have any type of data, one person is simply a string of lengths 1. It can be used to access members from the chain.

Example:

a = "Hello, World!"
print(a[1])

To getting expect level training for Python training in your Location – Python Training in Chennai | Python Training in Bangalore | Python Training in Pune | Python Training institute in Chennai Python Interview Questions | Python Course in Chennai

Leave a Reply

Your email address will not be published. Required fields are marked *