Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
# Example of Inheritance in Python
# A Parent Class (Base class) Employee having its own functionality
class Employee:
# Constructor of the Employee Class
def __init__(self, designation):
self.designation = designation
#!/usr/bin/python
# string representation of a list
strList = "[String, to, List, 1, 2 ,3]"
# # printing string variable and its type
print (strList)
print (type(strList))
# using strip and split and assign to the list variable
#!/usr/bin/python
# A custom function to convert string to list
def convertStrToList(myStr):
myList = list(myStr.split("_"))
return myList
# Declaring a string
myStr = "String_to_List"
#!/usr/bin/python
# A custom function to convert string to list
def convertStrToList(myStr):
myList = list(myStr.split(" "))
return myList
# Declaring a string
myStr = "String to List"
#!/usr/bin/python
# Declaring list which contains both string and integer elements
listStrInt = ['List', 'to', 'String', 2, 0, 1, 9]
# convert list to string using join and map functions
listToStr = ' '.join(map(str, listStrInt))
print(listToStr)
#!/usr/bin/python
# Declaring list which contains both string and integer elements
listStrInt = ['List', 'to', 'String', 2, 0, 1, 9]
# convert list to string using join and type conversion
listToStr = ' '.join([str(data) for data in listStrInt])
print(listToStr)
#!/usr/bin/python
# A custom function to convert list to string
def convertListToString(listStr):
# Declaring the string to store output
strOutput = " "
# return string using join() function
return (strOutput.join(listStr))
#!/usr/bin/python
# A custom function to convert list to string
def convertListToString(listStr):
# Declaring the string to store output
strOutput = ""
# iterating through the list
for data in listStr:
#!/usr/bin/python
# A custom function to convert list to string
def converttoStr(listChar):
# Declaring the string to store output
output = ""
# traversing the list of chars
#!/usr/bin/python
#assign employee Id to list1 of size 5
empId = ['1', '2', '3', '4', '5']
#assign employee name to list2 of size 4
empName = ['Tom', 'Maddy', 'Sam', 'John']
#assign employee age to list3 of size 6
empAge = [29, 30, 28, 32 ,33 , 34]