Topics covered:
- Flow of execution
- Strings
- String concatenation
- Data types (strings, integers)
- Using the file editor to write programs
- Saving and running programs in IDLE
- The print() function
- The input() function
- Comments
- Case-sensitivity
Learn to: store text in variables, combine text, and display text on the screen
Strings
string: a text value
- string values can be used just like integer and float values
- can store strings in variables
- string values start and end with a single quote (‘)
- or a double quote (“)
- Ex:
>>> spam = ‘hello’
>>> spam
‘hello’
>>> spam = “hello”
>>> spam
‘hello’
NB: Single or double quotes tell Python where the string begins and ends; they are not part of the string value{?}
- strings can comprise of any keyboard character with no character count limit;
- Examples:
-‘Hi there!’
-‘KITTENS’
-‘7 apples, 14 oranges, 3 lemons!!’
-‘0*&#wY%***05FDLKJ okay therkjlajksf568415224599@#$#$!’
String Concatentation
string concatentation: the combination of two strings with the + operator
- Just like integer and float values do, string values can combine with operators to make expressionsExample:
>>> ‘Hello’ + ‘World!’ [expression]
‘HelloWorld!’ [expression evaluates to a single string value]
>>> ‘Hello’ + ‘ World!’ [notice the single space after the first single quote]
‘Hello World!’
- + operator works differently on string values vs. integer and float values because they are different data types
- All values have a data type
Example:The data type of the value ‘Hello’ is a string.
The data type of the value 5 is a an integer.
data type: tells Python what operators should do when evaluating expressions
- + operator will concatenate string values but add integer and float values

NB: Different error types depending on the first value
Hello World!

How it works
- Each line of code is an instruction interpreted by the Python interpreter software (will be referred to as Python from now on)
- These instructions make up the program
Execution: the step Python is at in the program;
ex: when the program starts, the execution is at the first instruction; after executing the instruction, the execution moves down to the second instruction, and so on etc.
Comments
#This is a comment
This instruction is a comment : any text following a # sign (pound sign)
- Comments are for the programmers — notes of what their code does, usually at the top of the code
- Comments are ignored by Python
Functions
Function:
-mini-program inside the ‘main’ program
-contains instructions to execute when the function is called
Built-in function: Python-provided function; ex: print(), input()
Function call: an instruction that tells Python to run the code inside the function*
Example:
>>> print(‘Hello World!’) [function call – a call to the print() function]
*The code inside built-in functions such as print() are not visible to us
A program calls the print() function – Python takes the string between the parentheses as input and displays the text on the screen
QUESTION: what is the visual difference between a function and a function call?
argument: the value between the parentheses in a function call
Example: ‘Hello World!’ is the argument in print(‘Hello World!’)
passing the argument to the print() function – argument(s) inputted between the parentheses {?}
input() function
>>> myName = input() [an assignment statement]
Variable: myName
Function call: input()
When the function input() is called, the program waits for the user to enter text.
The text string the user enters becomes the value that the function call evaluates to.
NB: Function calls can be used in expressions that values can be used in.
return value: the value that the function call evaluates to/returns
In the case of the input() function, the return value is the string that the user typed in.
Example:

The user typed in May.
The input() function call evaluates to the string ‘May’.
The string ‘May’ gets stored in the myName variable.
Using Expressions in Function Calls
>>> print(‘It is good to meeet you, ‘ +myName) [print() function call]
NB: Arguments are always single values.
- Python evaluates this expression
- Pass that value as the argument
If Albert is the value stored in the myName variable, the evaluation would progress like this:

Ending the Program
A program terminates/exits: stops running
when the program executes the last line
- Python forgets all of the values stored in the variables, until the program runs again; ex:
the string stored in myName; when the program runs again and you enter a different name, the program will use that as your name
Naming Variables
- Variable names are case-sensitive; ex: SPAM, spam, Spam, sPAM — are four different variables in Python
- A bad idea to use different case variables; use descriptive names instead
- Variable names are usually lowercase
- Short names are better than long names
- If there is more than one word in a variable name, capitalise each word after the first word
- Or add underscores; ex: first_country