This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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