CSC Strings
CSC Strings
1|P age
11 What will be the output of following program:
a='hello'
b='virat'
for i in range(len(a)):
print(a[i].upper(),b[i])
12 What will be the output of following program:
print("xyyzxyzxzxyy".count('xyy', 2, 11))
13 What will be the output of following program:
print(“hello”+1+2+3)
14 What will be the output of following program: str1 = "PYTHON4CSIP.COM"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
15 What will be the output of following program: str =
"my name is kunfu pandya";
print (str.capitalize())
16 What will be the output of following program: str1 =
'Hello'
str2 ='World!'
print('str1 + str2 = ', str1 + str2)
print('str1 * 3 =', str1 * 3)
17 What will be the output of following program: count = 0
for letter in 'Hello World': if(letter == 'l'):
count += 1 print(count, 'letters found')
18 What will be the output of following program:
s="python4csip" n
= len(s)
m=''
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'): m =
m + s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'): m
= m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower() else:
m = m + '#'
print(m)
19 What will be the output of following program:
a = "Mahender Singh Dhoni"
a = a.split()
b = a[0][0]+". "+a[1][0]+". "+a[2]
print (b)
20 What will be the output of following program:
s='Mahender, Singh, Dhoni'
s1=s.split() for i
in s1:
print(i)
2|P age
21 What will be the output of following program:
"Welcome to Python4csip.com".split()
22 What will be the output of following program:
str ='Hello Python'
print (str) print
(str[0])
print (str[2:8])
print (str[3:])
print (str * 3)
print (str + "String")
23 What will be the output of the program?
line = "PYTHON IS EASY TO LEARN"
L = line.split('a') for i
in L:
print(i, end=' ')
24 What will be the output of following program:
s='mahender, singh, dhoni'
s1=s.split() for i
in s1:
if(i>'n'):
print(i.upper()) else:
print(i)
25 What will be the output of following program:
my_string = 'PYTHON4CSIP'
for i in range(len(my_string)):
print (my_string)
my_string = '#'
26 What will be the output of following program:
str="Python4csip.com"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print(str[i],end='')
27 What will be the output of following program:
str="AB145CVD124N"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print('#',end='')
3|P age
28 What will be the output of following program:
str="PYTHON4CSIP"
for i in range(len(str)):
if(str[i].isdigit()):
print(str[i],end='') if(str[i]=='N'or str[i]=='Y'):
print('#',end='')
29 Write a Program to Count the Number of Vowels in a String.
30 Write a Program to Take in a String and Replace Every Blank Space with Hyphen.
31 Write a Program to Calculate the Length of a String Without Using a Library Function
32 Write a Program to Calculate the Number of Words and the Number of Characters
Present in a String
33 Write a Program to Take in Two Strings and Display the Larger String without Using Built-in
Functions
34 Write a Program to Count Number of Lowercase Characters in a String
35 Write a Program to Check if a String is a Palindrome or Not
36 Write a Program to Calculate the Number of Upper Case Letters and Lower Case Letters in a
String
37 Write a Program to Calculate the Number of Digits and Letters in a String.
38 Write a Program to Form a New String Made of the First 2 and Last 2 characters From a
Given String
39 Write a Program to Count the Occurrences of Each Word in a Given String Sentence
40 Write a Program to Check if a Substring is Present in a Given String
41 Write a Python Program to check First Occurrence of a Character in a String
42 Write a Python Program to find ASCII Value of a Character
43 Write a Python Program to Remove Last Occurrence of a Character in a String.
4|P age