- boolean
- integer
- float
- string
- list
- dictionary
- None
Booleans
Boolean variables can be on or off, or True or False. Python defines Booleans with True and False. Note python requires that this is case sensitive.To create a variable and assign it a Boolean value:
item_for_sale = True item_sold_out = False
Integers
Integers are whole numbers. These tend to be easier for a computer to process when compared to floats.To create a variable and assign it an integer value:
number_in_stock = 123 number_sold = 7
Floats
Floats are numbers which feature a decimal point often when more precision is needed or dealing with continuous data.
To create a variable and assign it an float value:price = 2.99 tax = 0.17
Strings
Strings are finite sequences of characters. Strings are notated in python between quotation marks or inverted commas. There is an option to use 3 quotation marks or inverted commas in a row for strings that may contain these characters.To create a variable and assign it an string value:
customer_name = "Max Python" customer_address_1 = '1 house road' customer_address_2 = """S'ton Town""" customer_address_3 = '''AB1 2CD'''
Lists
Lists are a countable ordered sequence of values. The values of a list can be any datatype include nested lists.To create a variable and assign it an list value:
customer_basket = ["apple","pear","pear"] customer_sale = [customer_basket, True, "01/07/2017"]
Dictionaries
A dictionary is an array of values that have an associated key. The values of a dictionary can be any datatype, though keys should a unique string.To create a dictionary which contains the keys "name" and "DOB", with respected values of "dean" and "01/03/2017". Note that the curly brackets contain the dictionary information. Items are separated by a comma. Keys are presented first allowed by a colon then the value.
customer_basket = {'name': 'dean', 'DOB': '01/03/2017'}
None
The None datatype signifies that the variable has not been assigned a value.customer_discount = None
Related Sections
Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.Tkinter - Learn the key features of the tkinter to allow you to create user interfaces for your python programs.
Related Pages
Pickle - The pickle library allows a program to save data in a binary file.Python - List Comprehension - Create powerful list comprehension expressions.
Python - Generators - Learn about generator statements.
Python - Data types - The learn about the key datatypes in the python language.
Tkinter - Combo Box - This is a short example showing how to use combo boxes in a GUI.
Tkinter - Radio Buttons - A short example of how to create a GUI with radio buttons.
Tkinter - Canvas - Canvas allows for a range of shapes to be plotted, such as circles, squares, lines