LynxLee LynxLee - 2 months ago 16
Python Question

PySchools - Topic 1 Question 7

I was running through some practices for Python on PySchools.com and got stuck here. I'm sure it's a simple task. Anyone?

You can make use of the len(x) function to find out the number of characters in a string.

Examples

>>> greetings = "Hello World"
>>> len(greetings) # get the length of string
11
>>> greetings[0] # get the 1st character
'H'


Question here below:

greeting = "Hello Google!"
# number of characters stored in the variable greeting
number_of_char = len(greeting)

# repeat the greetings based on the number of character in 'greeting'
greetings =


http://www.pyschools.com/quiz/view_question/s1-q7

Answer

You can multiply a string by an integer in order to repeat the string multiple times.

>>> 'abc' * 2
'abcabc'
Comments