Python 1.1.0 Help

Basic Datatypes, Operators, and Structures - Examples

Basic Datatypes

  1. str

exampleVar = "Hello World"
  1. int

exampleVar = 1
  1. float

exampleVar = 1.1
  1. list

exampleVar = ["Hello", "World"]
  1. tuple

exampleVar = ("Hello", "World")
  1. dict

exampleVar = {"labelStr": "Hello World", "labelFlt":1.6}
  1. bool

exampleVar = True

Basic Math Operators

  1. +

exampleVar = 9 + 2
exampleVar = "Hello" + "World"
  1. -

exampleVar = 9 - 2
  1. *

exampleVar = 9 * 2
  1. /

exampleVar = 9 / 2
  1. //

exampleVar = 9 // 2
  1. %

exampleVar = 9 % 2

Basic Structures

  1. Functions

def exampleFunc(name): message = f"Hello {name}, how are you today?" return message
  1. Loops

repeatNumber = 10 for name in range(repeatNumber): print("Hello World")
  1. Conditionals

number = 10 if number == 10: print("This will print only if the variable 'number' is given the value: 10") elif number == 20: print("This will print only if the variable 'number' is given the value: 20") else: print("This will print only if the variable 'number' has neither values 10 nor 20")
  1. Try Statements

try: print("This will print if the code within the try statement runs successfully") except print("This will print if the code within the try statement excounters an error")
Last modified: 25 May 2024