PYTHON
  • PYTHON v3
  • Python IDE Setup
  • Python Programming
    • Python for ABS
      • Resources
      • Ch1 - Getting Started
      • Ch2 - Types, Variables and Simple I/O
  • Python For Network Engineers-Kirk Beyers
    • Resources
    • Python Fundamentals
  • Python Inststitute (PCAP)
    • Resources
    • Course Introduction
    • Python Essentials (Part 1)
      • Module 1
        • Fundamentals
        • What is Python
        • Starting your work with Python
      • Module 2
        • The Print Function
          • Section Summary
        • Literals
          • Section Summary
        • Operations- Data Manipulation Tools
          • Section Summary
        • Variables
          • Leaving Comments in Code
          • The input () Function
  • 100 Days Of Code
    • Resources
    • What You Have To Do !!
    • 100 DAY's
      • DAY 1: Working with Variables
      • Day 2: Data Types & String Manipulation
      • Day 3: Control Flow and Operators
      • Day 4: Randomisation and Lists
      • Day 5: For Loops, Range & Code Blocks
      • Day 6: Python Functions and Karel
      • Day 7: Hangman
      • SUMMARY
  • {Pirple}
    • Resources
Powered by GitBook
On this page
  • Module Objectives
  • Using Quotes Inside Strings
  • Printing Multiple Values
  • Specifying a Final String to Print

Was this helpful?

  1. Python Programming
  2. Python for ABS

Ch2 - Types, Variables and Simple I/O

Module Objectives

  • Use triple-quoted strings and escape sequences to manipulate text

  • Make programs do maths

  • Store data in computers memory

  • Use variables to access and manipulate that data

  • Get input from users to create interface programs

Using Quotes Inside Strings

When creating strings we surround them with quotes. Can either be single or double quotes.

>>>print ("Program 'Game Over' 2.0") Program Program 'Game Over' 2.0

The double quotes above are like bookends. They tell the computer where the string starts and ends, so you can use as many single quotes you want between the "bookends" This would be the same if the bookends were single quotes, you can use as many double quotes between the single quote bookends as you want.

>>>print ('Program "Game Over" 2.0') Program "Game Over" 2.0

Printing Multiple Values

You can print multiple values with a single call to the print () function, just like multiple arguments separated by commas. >>>print ("Same", "message", "as before") Same message as before

Notice that each value is printed with a space as a separator. This is default behaviour of the print () function. You can separate them over multiple lines, the result will be the same. Sometimes used to break up code for easier reading. >>>print ("Just", "a bit", "bigger") Just a bit bigger

Specifying a Final String to Print

Specifying the print() function prints a newline character as a final value (i.e. it returns carriage to a new line >>>

This can be changed and instead of the final string being printed is a newline, you can define what the final sting to print will be. You could specify that a space could be the final character to be printed and not a newline when you call the print () function This would mean a subsequent print () function

PreviousCh1 - Getting StartedNextResources

Last updated 4 years ago

Was this helpful?