Getting Started with python

Nikhil Pandey
3 min readMay 11, 2023

--

⏮️previous page ⏭️next page

The smallest individual unit in a program is known as token or a lexical unit.

Python tokens are:

  1. keywords

keywords are predefined words with the special meaning to the language compiler or interpreter. They are reserved for special purpose you can’t use them as normal identifier names.

python programming contains the following keywords;

2. Identifiers (Names)

Identifiers are the names given to different parts of the program viz. variables, objects, classes, function, lists, dictionaries and so forth.

  1. Non-keyword type means you can’t include any keyword here.
  2. Only letters, numbers, and underscores(_) are allowed.
  3. Variable names can’t begin with the number.
>>>fruits=['apple','mango','cherry']
>>>#valid variable type
>>>#making invalid variable type
>>>123fruit=['apple']
>>>SyntaxError: invalid decimal literal

Literals: Literals are data items that have fixed or constant value.

⭐ string literals: A string literals is a combination of characters surrounding by single line or multi line quotes.

⭐single line strings: Must terminate in one line.

⭐multiline string: spread across multiple lines.

>>>text1='hello word'
>>>text2=''' this
...is multiline
...string '''

Numeric Literals:

⭐Decimal form

#this is a comment
>>>q=1.0
>>>type(q)
<class 'float'>

⭐octal form

#this is a comment
print(oct(10))

#another code
#Binary to Octal
print(oct(0b110))

# Hexa to octal
print(oct(0XB))

⭐hexadecimal form

A type of number system, that has a base value equal to 16

#this is a comment
x=hex(255)
print(x)

Boolean Literals:

>>>a=10
>>>b=10
>>>a is b
True
>>>a=10
>>>b=12
>>>a is b
False

Special literal None

#None represents absence of value

>>>a=None
>>>type(a)
<class 'NoneType'>

Operators

Arithmetic operator

# addition
>>>x+y
#substraction
>>>x-y
#division
>>>x/y
#multiplication
>>>x*y
#floor division
>>>x//y
#modulus
>>>x%y
#Exponentiation
>>>x**y

Boolean operator

print(10 > 9)
print(10 == 9)
print(10 < 9)

Bitwise operators are used to compare (binary) numbers

# Python program to show
# bitwise operators

a = 10
b = 4

# Print bitwise AND operation
print("a & b =", a & b)

# Print bitwise OR operation
print("a | b =", a | b)

# Print bitwise NOT operation
print("~a =", ~a)

# print bitwise XOR operation
print("a ^ b =", a ^ b)

⭐Identity Operators

>>>a=10
>>>b=10
>>>a is b
True

>>>a=10
>>>b=10
>>>a is not b
False

⭐Relational Operators

operand1 = 89
operand2 = 569

print(operand1 > operand2)

#another code

operand1 = 659
operand2 = 569

print(operand1 == operand2)

#another code

operand1 = 659
operand2 = 569

print(operand1 != operand2)

⭐Logical Operator

#this is a comment!
x = 5
print(x > 3 and x < 10)
# returns True because 5 is greater than 3 AND 5 is less than 10

#comment

x = 5
print(x > 3 or x < 4)
# returns True because one of the conditions are true (5 is greater than 3, but 5 is not less than 4)

#comment

x = 5
print(not(x > 3 and x < 10))
# returns False because not is used to reverse the result

⭐Punctuators

Punctuators are ‘symbols’ that are used in programming language.

That’ll for today! Bye (please mail me if your find anything to be improved. pandeynikhilone@gmail.com) or Have any suggestion! fill form

⏮️previous page ⏭️next page

--

--

Nikhil Pandey

I am a student and a programming nerd. I learn and teach topics to help my fellow readers understand and apply their programming knowledge fluently.