String concatenation
-----------------------------------------
String : We know string is a collection of characters in single or double quotes.
Concatenation : Joining of strings.
Join the strings with + sign
If we want to space between the strings then use " "
String can join with only string not with a number. If we join number with string then error occurs.
print (first_name + 2) TypeError
If we want to join number with string then use
1 ) Number in quotes : " 2 "
or
2 ) String function : str (2)
Note : By using multiplication * sign , string can be print in multiple of it.
User Input
----------------------
Input function : To take input from user in string.
We take input from user and assign that input value in variable.
variable = input ( " Message to show " )
Tutorial 1
name1 = input ( " Type your name : " )
Then input will be ask in output
Type input value as string in output.
This Pankaj string will be stored in the variable name1.
Tutorial 2
We can concatenate ( join ) input with other strings...
1) First we take input from user
eg. nameA = input ( " Enter your name : " )
2) Then that stored input join with another strings as follows
eg. print ( " Hello " + nameA + "\n Good Morning , Have a good day" )
Then run the file in terminal.
Then give the input string Pankaj and press enter.
Output will be show concatenated strings with variable.
* Just example *
Que. Type the code for following output.
Hii Pankaj Gade ,
You are 23 years old.
Have a Good day
Bye..
-----------------------------------------
String : We know string is a collection of characters in single or double quotes.
Concatenation : Joining of strings.
Join the strings with + sign
If we want to space between the strings then use " "
String can join with only string not with a number. If we join number with string then error occurs.
print (first_name + 2) TypeError
If we want to join number with string then use
1 ) Number in quotes : " 2 "
or
2 ) String function : str (2)
Note : By using multiplication * sign , string can be print in multiple of it.
User Input
----------------------
We take input from user and assign that input value in variable.
variable = input ( " Message to show " )
Tutorial 1
name1 = input ( " Type your name : " )
Then input will be ask in output
Type input value as string in output.
This Pankaj string will be stored in the variable name1.
Tutorial 2
We can concatenate ( join ) input with other strings...
1) First we take input from user
eg. nameA = input ( " Enter your name : " )
2) Then that stored input join with another strings as follows
eg. print ( " Hello " + nameA + "\n Good Morning , Have a good day" )
Then run the file in terminal.
Then give the input string Pankaj and press enter.
Output will be show concatenated strings with variable.
* Just example *
Que. Type the code for following output.
Hii Pankaj Gade ,
You are 23 years old.
Have a Good day
Bye..
Note : Here 23 is stored as string. Not as a number.