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
  • Key Takeaways
  • Exercise

Was this helpful?

  1. Python Inststitute (PCAP)
  2. Python Essentials (Part 1)
  3. Module 2
  4. Literals

Section Summary

Key Takeaways

  • Literals are notations for representing some fixed value in code. Python has various types of literals:

    • a literal can be a number (numeric numbers e.g.123)

    • or a string (string literals e.g. "I am a literal")

  • The binary system is a system that uses 2 as the base and is made up of 0's and 1's

  • The octal system is a system that uses 8 as the base

  • The hexadecimal system uses 16 as the base and uses the decimal numbers and A-F letters

  • Integers are whole positive or negative numbers

  • Floats or Floating Point are numbers that contain a fracrional componenet (e.g. 1.27)

  • To encode an apostrophe or quote inside a string you can either use the escape character eg 'I\'m happy.' or open and close the string using an opposite set of symbols (double quote) to the ones you which to encode eg "I'm happy" to encode an apostrophe, and a single quote to encode a double quote eg. 'He said "Python", not "Typhoon" '

  • Boolean values are either True or False and represented by 1 and 0 respectively

  • There is another type of literal: the None literal and is used to represent the absence of a value

Exercise

Exercise 1

What types of literals are the following two examples? "Hello ", "007" They are both strings/string literals

Exercise 2

What types of literals are the following four examples? "1.5", 2.0, 528, False They are string, floating-point, integer and Boolean literals

Exercise 3

What is the decimal value of the following binary number? 1011 - The answer id 11 8 4 2 1 1 0 1 1 ------- Add up 8+2+1 = 11

PreviousLiteralsNextOperations- Data Manipulation Tools

Last updated 4 years ago

Was this helpful?