Skip to main content

Strings and Strings operations in Python.

 Strings:

If you want to enter text in python, you have to use a string. A string is created by entering text between two single or double quotation marks ("Text" or 'Text').

Some characters can't be directly included in a string. Say for example the double and single quotes can not be directly included in a double or  single quote string. This will end the code prematurely and can cause error.






  • You can enter these kind of symbols by using { \ } before them. Other common characters that must be escaped are newlines and backslashes. Double quote only need to be escaped in double quote and is true for single quote as well.

    Note : Backslash can also be used to escape tabs, arbitrary unicode characters, and various other things that can't be reliably printed. These characters are called as escape characters.


    Newlines:

    We can create a newline or escape a newline in python using {\n} in place from where you want to start the new line. But python provides an easy way to avoid manually written "\n"
    to escape to a newline in a string. The method is as : Create a string with three sets of quotes , and newlines that are created by pressing enter are automatically escape.

String Operations:

" Concatenation : The state of being linked together as in a chain or union in a linked series "
As with the integers and floats, strings in python can be added, using a process called concatenation, which can be done on any two strings.
When concatenating a string it doesn't matter whether they've been created with single or double quotes.Even if your strings contain numbers they are still added as strings rather than integers.

Adding a string to a number produces an error, even they might look similar they are two different entities.
You can also multiply a string with an integer.






 


Comments

Post a Comment

Popular posts from this blog

First Program : Python For Beginner

 Python : Python is high level programming language with application in numerous areas including web programming, scripting, scientific computing, and artificial intelligence. First Program: "Hello World" So let's take our first foot into the world of Python.Open the console and type :                    print("Hello World") and press enter.                                                                                                                                                                       Hurry!! you have just created your first program. But remember python is case sensitive here P & p are different for python, so be careful about this. Printing Text :  The print statement can also be used to output multiple lines of text. To do so you have to use three quotation marks{"} and put the text between them.   There are some other methods as well for the multiple line text output, like instead of using three quotation marks we can use {\n

Introduction To Python : Python For Beginners

What is Python ? Python is the most popular general purpose (Multi purpose) programming language now a days.It's used in almost everything  from machine learning to software development.   Python is a high level programming language with application in numerous areas, including web programming, scripting, scientific computing and artificial intelligence.Python is processed at runtime by the interpreter .It focus on object oriented programming and code readability. Why Python ? It's easy to learn :  Python doesn't have very complex syntax structure so it is easier to learn python than the other programming languages. Simple syntax means time needed to learn  python is shorter from many other programming languages. Teaching Python is easy : As we know that the syntax of python programming is simple so teaching it will be easier.Thus the teacher can put more time and energy in general programming techniques. Understanding the python code is easy : Due to its simplicity and its