View inherit1.py
#!/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 |
View listtostr8.py
#!/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 |
View listtostr7.py
#!/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" |
View listtostr6.py
#!/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" |
View listtostr5.py
#!/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) |
View listtostr4.py
#!/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) |
View listtostr3.py
#!/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)) |
View listtostr2.py
#!/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: |
View listtostr1.py
#!/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 |
View zip6.py
#!/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] |
NewerOlder