How to Assign Strings to Variables in Python

Sword Code
0

String

The string is the set of letters or words to a simple sentence that is stored in a variable, this is usually used while taking input because it is used in applications whether it is a PC, web-based, or mobile application. A simple example of this is when an application or web-based account asks you to enter your name and about in your profile or any other personal data or information, that data is stored in a variable inside of a server along with the string data type.
It is also used in office programs while entering data/information about clients into to server or PC. To create a variable to store the string in a variable we have to write it in Quotation marks (" ") as the quotation mark works as a keyword indicating the presence of string Data Type as in Python we don't have to declare data type.

Format:

It is very simple and easy to assign variables in Python as compared to other languages like Java, C, C++, etc.
First, declare the variable name and use an equal sign then in double quotes write the string you want to assign the variable. 

Varialble name = "String"
As shown

Examples 

Example 1:

Assigning string  "Swrod Code z" to a variable.

Code:

a = "Sword Code z"
print("The String is: ",a)

Output:

The String is: Sword Code

Example 2:

Declare variable name id_name and store your name in it.

Code:

id_name = "Robert"        #can add any name here
print("YO! Are you ",id_name," \nAs it's what you entered as your name")

Output:

YO! Are you Robert 
As it's what you entered as your name

To see the simulation click on the simulation button below.

Post a Comment

0Comments

If you have any type of issue or request leave an comment so that we can handle it

Post a Comment (0)