Python Basics
This section of the book will cover the basic skills to create variables, obtain keyboard inputs through the console, output data to the console, and do mathematical calculations.
Major Definitions
Variable: A container that holds data for a program.
Function: A built-in or custom segment of executable code.
Comment: Human readable notes written by a programmer for others to read. Often used to describe certain aspects of the code.
Whenever we name a variable or a function we create an Identifier.
Rules for Identifiers:
Cannot use Keywords as identifier names
No punctuation characters
An identifier should always start with letters (A-Za-z) then followed by alphanumeric characters ... an identifier cannot start with numbers (0-9)
Identifier Naming Conventions
You donโt start a variable with capitals
There are no white spaces, we connect multi word variables with either camelCasing or under_scores.
Variable names should be effective and short, not vague.
Example of a Python Code using an Identifier
# Our First Line of Python Code
is an example of acomment
. The#
symbol creates a single line comment.user_name = "Jane Doe"
is an example of avariable
containing the data"Jane Doe"
; it is using theunder_score
naming conventionprint(user_name)
is an example of using a function to output a value to the console.
Last updated