Python Short Notes

Python Short Notes

Basic Syntax

  • identation (4 spaces)
  • for comments use # comment
  • for multiline comment use

''' comment '''

  • for Output in console : print()

variables

  • container to store data
  • starts with letters and underscore _
  • to assign varible use = operator

eg: x=5

  • to assign multiple variables in single line

eg: a,b,c=1,2,3

Data Types

  • Integer int(3)

  • Float float(3.12)

  • complex complex(3,2)

  • List : [1,2,3]

  • Dictionary :

  • Set : set()

  • tuple : ()

  • frojen set : ()

Conditional statements

if elif else

  • Conditional statements allow you to execute certain parts of your code based on specific conditions.
if condition:
    # code block to execute if condition is true
elif another_condition:
    # code block to execute if another_condition is true
else:
    # code block to execute if all conditions are false

for loop

A for loop is used for iterating over a sequence (such as a list, tuple, dictionary, set, or string).

for i in range(5):
    print(i)

while loop

A while loop is used to repeat a block of code as long as a condition is true.

count = 0

while count < 5:
    print(count)
    count += 1
Team
Team

This account on Doubtly.in is managed by the core team of Doubtly.

Articles: 475