Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Question

1. Name: John
Age: 30

2. Name: Miky
Age: 26
Adress: Yangon
Id no: 123456

3. Create a variable named carname and assign the value Volvo to it and print value.

4. Create two variables named employeName and address and then assign the value Mike
and Yangon to it and print value.

5. Write a program to accept name and address from the user and then print value.

name=
address=input
print()
print()

6. Write a program to accept two numbers from the user and calculate multiplication
7. Display three string “Name”, “Is”, “James” as “Name**Is**James”

8. Accept any three string from one input() call. Write a program to take three names as
input from a user in the single input() function call.

Expected Output

Enter three string Emma Jessa Kelly

Name1: Emma

Name2: Jessa

Name3: Kelly

9. Initial String:
GeeksForGeeks//Hello
First character of String is:
G
Last character of String is:
S

10. Initial String:


Greenhacker
The length of string is 11

11. Initial String:


GeeksForGeeks
Slicing characters from 3-12:
ksForGeek
Slicing characters between 3rd and 2nd last character:
ksForGee

12. Create a variable named string1 from the user enter input string. And then print first
character and last character of this input.

13. Create a variable named my_name and assign the string value “Kyaw Kyaw” to it and
print reverse a string.
Output is : wayK wayK
14.

Deleting/Updating from a String


15. Initial String:
Hello, I'm a Geek
Updating character at 2nd Index:
Heplo, I'm a Geek
Heplo, I'm a Geek
Updating Entire String
16. assign a value to ‘String1’ and then updated it by assigning a completely different value
to it
Initial String:
Hello, I'm a Geek
Updated String:
Welcome to the Geek World

Deleting a character
17. Initial String:
Hello, I'm a Geek
Deleting character at 2nd Index:
Traceback (most recent call last):
File "e:\GFG\Python codes\Codes\demo.py", line 9, in <module>
del String1[2]
TypeError: 'str' object doesn't support item deletion

18. We will first slice the string up to the character that we want to delete and then
concatenate the remaining string next from the deleted character.

Initial String:
Hello, I'm a Geek
Deleting character at 2nd Index:
Helo, I'm a Geek

Python String Exercise with Solutions – String Programs for Practice (pynative.com)

You might also like