0% found this document useful (0 votes)
27 views2 pages

String and List Handling in Python

The document provides examples of string handling in Python, including finding string length, concatenation, and checking if strings are numeric or alphabetic. It also demonstrates list methodologies such as creating a list, adding elements, inserting, removing, and reversing the list. Additionally, it shows how to extend a list with tuple elements and count occurrences of an item.

Uploaded by

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

String and List Handling in Python

The document provides examples of string handling in Python, including finding string length, concatenation, and checking if strings are numeric or alphabetic. It also demonstrates list methodologies such as creating a list, adding elements, inserting, removing, and reversing the list. Additionally, it shows how to extend a list with tuple elements and count occurrences of an item.

Uploaded by

foxy91015
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

STRING HANDLING

#Finding String length


string1 ='Hello Python'
print (len(string1))

#Concatenating Strings

string2=' World'
print (string1 + string2)
num=100
print (string1 + str(num))

#Print a String multiple times


print (string1 *10)

str1 ='Hello'
print ([Link]())

str2 ='12345'
print ([Link]())

print ([Link]())
print ([Link]())

str6 = 'Python Programming Language'


print ([Link]('e'))
print ([Link]('age'))
print ([Link]('Language'))
print ([Link]('Programming Language'))
print ([Link]('Programming'))

str7 = 'Python is a Programming Language, Python is an Open source software'


print (str7)
print ([Link]('Python', 'JavaScript'))
List Methodologies
# creating an empty list
My_List = []

# number of elements as input


n = int(input("Enter number of elements : "))

# iterating till the range


for i in range(0, n):
element = (input())
# adding the element
My_List.append(element)
print("This is My_List of elements", My_List)

# extending tuple elements


My_List.extend((6, 4))
print("List after extended: ", My_List)

#inserted at index 3 (4th position)


My_List.insert(3, '5')

print('After Insterted:', My_List)

#remove 9 from the list


My_List.remove(4)
print('After removed:', My_List)

# get the index of 'dog'


index = My_List.index('5')
print("The index position of element in the list is:",index)

# check the count of 2


count = My_List.count(3)
print("Count of 3: ", count)

# reverse the order of list elements


My_List.reverse()
print("Reversed List:", My_List)

You might also like