REPL : Read Evaluate Print Loop
IDE : Integrated Development Editor
An Identifier is a name given to entities like class, functions, variables etc.
A variable is a named area of the computers’ memory that can be used to hold data.
- A variable name can only contain alpha-numeric characters and underscores (A-Z, a-z, 0-9, and _ )
- Variable should not start with a number.
- Python Keywords are not allowed as variable names.
- Variable names are case-sensitive.
The type of the data held by a variable can Dynamically change as the program executes. Many programming languages such as Java, C and C# where variables are Statically Typed.
Keywords are a list of reserved words that have predefned meaning. Keywords are special vocabulary and cannot be used by programmers as identifers for variables, functions, constants or with any identifer name.
There are 35 Keywords in python3.8. This number can vary slightly over the time.
>>> help('keywords')
Here is a list of the Python keywords.
False class from or
None continue global pass
True def if raise
and del import return
as elif in try
assert else is while
async except lambda with
await finally nonlocal yield
break for not- Numbers
- String
- Boolean
- None
Python has three type of numbers.
- Integer
Integers can be of any length; it is only limited by the memory available.
>>> a = 2 >>> type(a) <class 'int'>
- Float
It can store number with a fractional part.
>>> f = 3.14 >>> type(f) <class 'float'>
- Complex
Complex numbers are written in the form, x + yj, where x is the real part and y is the imaginary part.
>>> c = 2 + 3j >>> type(c) <class 'complex'> >>> >>> >>> m = 25 - 3.14j >>> type(m) <class 'complex'>
A string consists of a sequence of one or more characters, which can include letters, numbers, and other types of characters. A string can also contain spaces.+
>>> name = "Skill Disk"
>>> type(name)
<class 'str'>
>>>
>>>place = 'Bangalore'
>>> type(place)
<class 'str'>
>>>
>>> # can use Single quotes or Double quotes to represent strings.
>>>
>>> # MULTILINE STRING
>>> address = '''
... #333, 2nd Floor,
... Dr Rajkumar Road,
... Rajajinagar, 6th block,
... Bangalore - 560010
... '''
>>> # Multiline strings can be denoted using triple quotes, ''' or """. A condition is really just a yes-or-no question, the answer to that question is a Boolean value, either True or False. The Boolean values, True and False are treated as reserved words.
>>> condition = True
>>> type(condition)
<class 'bool'>
>>> # Boolean type has only two values. True False
None is another special data type in Python. None is frequently used to represent the absence of a value.
>>> x = None
>>> type(x)
<class 'NoneType'>
These are special symbols which help the user to carry out operations like addition, subtraction, etc.
- Arthmetic operators.
- Assignment operators.
- Logical operators.
- Comparison operators.
- Bitwise Operators.
| Operator | Operator Name | Example |
|---|---|---|
| + | Addition operator | |
| - | Subtraction operator | |
| * | Multiplication operator | |
| / | Division operator | |
| % | Modulus operator | |
| ** | Exponent operator | |
| // | Floor division operator |
| Operator | Operator Name | Example |
|---|---|---|
| = | Assignment | |
| += | Addition Assignment | |
| −= | Subtraction Assignment | |
| *= | Multiplication Assignment | |
| /= | Division Assignment | |
| **= | Exponentiation Assignment | |
| //= | Floor division Assignment | |
| %= | Remainder Assignment |
| Operator | Operator Name | Example |
|---|---|---|
| and | Logical AND | |
| or | Logical OR | |
| not | Logical NOT |
| Operator | Operator Name | Example |
|---|---|---|
| == | Equal to | |
| != | Not Equal to | |
| > | Greater than | |
| < | Lesser than | |
| >= | Greater than or equal to | |
| <= | Lesser than or equal to |
| Operator | Operator Name | Example |
|---|---|---|
| & | Binary AND | |
| | | Binary OR | |
| ^ | Binary XOR | |
| ~ | Binary Ones Complement | |
| << | Binary Left Shift | |
| >> | Binary Right Shift |
A comment is a text that describes what the program or a particular part of the program is trying to do and is ignored by the Python interpreter.
In Python, use the hash (#) symbol to start writing a comment.
>>> # This is Single line comment Use the hash (#) symbol at the beginning of each line.
OR
Use Triple quotes, ( ''' or """ )
>>> # This is Single line comment
>>> # Adding hash (#) again to the next line makes it Multiline comment.
>>>
>>>
>>> ''' Multiline comment can
... also be represented by using thriple quotes.
... Usually this type of commenting is used
... to represent DOC Strings in Python'''
>>>