Article Outline
Python example 'lesson1-PrintingAndStrings'
lesson1-PrintingAndStrings
Python beginners example: lesson1-PrintingAndStrings
# Run this program to see what it does, then look over the code.
# To print(text to the monitor we use the print(function.)
print("Hello World")
# Like all functions, print() get a set of parentheses, and the thing we put
# inside the parentheses is called an argument. Here, the argument "Hello World"
# is a string. A string is just a bunch of characters. We create strings by
# using quotation marks.
# If we use the print(function with no argument, it prints a blank line.)
print()
# We can also make variables that contain strings by using the equal sign.
myName = "Orndorff"
# Variables names are case sensative, so we have to use the same capitalization
# every time we type the varialbe name. It is standard to start your variable
# names with a lowercase letter, and start every subsequent letter with a
# capital letter like I did above.
print("My name is")
print(myName)
print()
# We can also join two strings together to make one big string. This process is
# known as concatenation and uses the + operator.
bigString = "My name is" + myName
print(bigString)
print()
# ---------------- Exercises -----------------
# 1. Modify line 4 so that is prints a exclaimation point after the text:
# Hello World!
# 2. Modify line 12 so that the string contains your name instead of my name.
# 3. Modify line 24 so that it prints a space between "is" and your name.
# 4. On line 31 make a new string variable containing whatever content you want.
# 5. On line 32 make print(your new string variable to the screen)
Useful links
- Learn Python: https://pythonbasics.org
- Download Python: https://python.org