python slots example

By admin  

python slots example
How to do something in Python?

Well I need help. How do you get a string and turn it into a tuple with every character of that string into a slot on that tuple? For example I want the string “Hello World” to appear into a Tuple like this: myTuple(”h”, “e”, “l”, “l”, “o”, ” “, “w”, “o”, “r”, “l”, “d”). How do I do that?

ok so
aString = “Hello World”
aList = []#this will hold the individual character from the string

for item in aString:
aList.append(item)

aTuple =tuple( aList) #get a tuple from the list

print aTuple

input()

Google Python Class Day 2 Part 3



Post a Comment

Your email is never shared. Required fields are marked *

*
*