01 Python Fundamentals CodeChum
01 Python Fundamentals CodeChum
Syntax:
• in order to store multiple sorts of data in the program
• utilized in the program to accomplish any operation or activity
Python has no command for declaring a variable.
• equal sign (=)
• used to assign values to variables
• variable’s name
• left of the = operator
• value stored
• right of the = operator
Multiple variables can also be assigned to multiple values.
• First character
• begin with either an alphabet or an underscore (_) or a dollar sign ($)
• strictly cannot begin with a number
• No special characters
• does not encourage the use of special characters
• cannot use special characters like the exclamatory mark or the @
symbol
• No keywords
• using keywords as identifiers is strictly forbidden
• No white spaces
• Leaving a gap between identifiers is discouraged
• Word limit
• use of an arbitrarily long sequence of identifier names is
restrained
• name of the identifier must not exceed 31 characters
• Case sensitive
• uppercase and lowercase characters connote different
meanings
• limit the kind of data that may be stored
• used to inform variables about the sorts of data they may hold
• declarations for variables
• identify the type of the variable when it declared.
• identify the type of the return value of a function.
• identify the type of a parameter expected by a function.
• determines the values that the variable can have
• attribute associated with a piece of data that tells a computer system
how to interpret its value
• include integers, floating-point numbers, and complex numbers
• defined as int, float, and complex classes in Python
• type() function
• determine which class a variable or value belongs to
• isinstance() function
• determines whether or not an object belongs to a specific class
Example:
Example:
Integers can be any length, limited only by the amount of memory available.
The formula for complex numbers is x + yj, where x is the real part and y is the
imaginary part.
Examples of Python Numbers:
• collection of items in a specific order
• one of Python’s most popular and versatile data types
• does not have to contain items of the same type
Example:
• a sequence of Unicode characters
• can be represented with either single or double-quotes
• multi-line strings can be denoted using triple quotes, ‘’’ or “”"
Example:
Just like a list and tuple, the slicing operator [ ] can be used with strings.
Strings, however, are immutable.
The plus + sign is the string concatenation operator and the asterisk * is the
repetition operator.
Example:
Example:
• unsorted group of unique items
• set is defined by values separated by a comma
• items are not ordered
Example:
• unsorted group of unique items
• set is defined by values separated by a comma
• items are not ordered
Example:
It is also possible to perform set operations such as union and intersection on
two sets. The values of sets are distinct. They take out duplicates.
For example:
Note that since set are unordered collection, indexing has no meaning.
Hence, the slicing operator [] does not work.
• a collection of key-value pairs that are not ordered
• used when dealing with large amounts of data
• defined inside braces, with each item being a key: value pair
Example:
Create a main.py:
NOTE: In reality, constants are not used in Python. They are typically given
names in all capital letters to distinguish them from variables.
However, it does not prevent reassignment.
1. Constant and variable names should have a combination of letters in
lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an
underscore (_)
2. Create a name that makes sense
3. Use capital letters possible to declare a constant
4. Use capital letters possible to declare a constant
5. Never use special symbols like !, @, #, $, %, etc.
6. Don’t start a variable name with a digit
• predefined, reserved words used in programming that have special
meanings to the compiler
• C is a case sensitive language
• all keywords must be written in lowercase
• used to change certain of the program’s functionalities