0% found this document useful (0 votes)
39 views3 pages

Variables: String Concatenation

The document discusses variables in Python. It notes that variables do not need to be declared, and can store numbers, strings, or other data types. Variable names must start with a letter or underscore, and can include numbers but no spaces. Strings can be concatenated using + and spaces added with quotes. User input is taken as a string using input(). Numbers and strings can be converted between types using int(), float(), and str(). Multiple variables can be assigned at once. String formatting is supported using .format() or f-strings. Variables are indexed from 0 at the start or -1 at the end of a string.

Uploaded by

Himanshu agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

Variables: String Concatenation

The document discusses variables in Python. It notes that variables do not need to be declared, and can store numbers, strings, or other data types. Variable names must start with a letter or underscore, and can include numbers but no spaces. Strings can be concatenated using + and spaces added with quotes. User input is taken as a string using input(). Numbers and strings can be converted between types using int(), float(), and str(). Multiple variables can be assigned at once. String formatting is supported using .format() or f-strings. Variables are indexed from 0 at the start or -1 at the end of a string.

Uploaded by

Himanshu agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

VARIABLES

➢ In python, we don’t need to declare variable.


➢ We can store any number or string (either by single quote or double quote) in the variable.

CONVENTION FOR THE NAME OF VARIABLE


➢ It should not start with the number
➢ It can contain only number, variable or underscore.

➢ User_one_name = “Harshit” or ’Harshit’ # snake case writing (generally preferred by python
coder)
➢ UserOneName = “Harshit” or ’Harshit’ # camel case writing

Note: To print any variable

Print (name of variable)

We can store many different data type at a time which make python most flexible coding
language.

➢ STRING CONCATENATION
➢ We can add two string by plus sign

NOTE : For space between them, use : “ ” or ‘ ‘

EX :

First_name = Himanshu

Print (First_name + “ ” + ‘Agarwal’ )

OUTPUT : Himanshu Agarwal


➢ USER INPUT
➢ Variable = Input (“message you want to convey”)
➢ NOTE: It always takes input as a string.


➢ INT , FLOAT AND STR FUNCTIONS
INT:
➢ To convert a string into integer.

EX : int(“4”) = 4

STR:
➢ To convert a number into string.

EX : str(4) = “4”

FLOAT:
➢ To convert a string/number into float value

EX : float(4) = 4.0

TO STORE MORE THAN ONE VARIABLE AT A TIME


➢ VAR1 , VAR2 , VAR3 , … = “STR1” , STR2” , number1 …..

TO STORE MORE THAN ONE INPUT AT A TIME


➢ Var1 , var2, var3 ….. = input (“Instruction for user to input”).split(“symbol”)

STRING FORMATTING
➢ 1.) python 3

Name = “Himanshu”

Age = 19

Print(“Hello {} your age is {} ”).format(name , age)

➢ 2.) python 3.6

Name = “Himanshu”

Age = 19

Print(f“Hello {name} your age is {age} ”)

STRING INDEXING
Name = “Himanshu”
LETTER INDEX FROM STARTING INDEX FROM LAST

H 0 -1

I 1 -2

M 2 -3

A 3 -4

N 4 -5

S 5 -6

H 6 -7

U 7 -8

NOTE: To print any letter

Print (name [index of that letter])

You might also like