Skip to content

Exercise 2.1: Strings and text

Alternative course

Strings and text

Any time you want to use text in Python, you are using strings.
Python understands you want to use a string if you use the double-quotes symbol.

Try the program below:

# Text
x = "Nancy"

# Combine numbers and text
s = "My lucky number is %d, what is yours?" % 7

# alternative method of combining numbers and text
s = "My lucky number is " + str(7) + ", what is yours?"

# print character by index

# print piece of string

What you see on success


Study drill

Try the exercises below

1. Make a program that displays your favourite actor/actress.
2. Try to print the word 'lucky' inside s.
3. Try to print the day, month, year in the form "Today is 2/2/2016".


Exercise 2: Variables
Exercise 2.2: Random numbers
Published inUncategorized

Be First to Comment

    Leave a Reply