Learn python in easy step. Python Basic Syntax

Python Variables

Variables are containers for storing data values. Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.

For Example:

X=10

Y=’’Jhon”

Print(x)

Print(y)

Output:

10

Jhon

Code run in vs code with screenshot:

 

Python For Loops

A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

Example:

fruits = ["apple", "banana", "cherry"]

for x in fruits:

  print(x)

Code run in vs code:


 

Python Variables

Variables are containers for storing data values. Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.

For Example:

X=10

Y=’’Jhon”

Print(x)

Print(y)

Output:

10

Jhon

Code run in vs code with screenshot:

 

Python For Loops

A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

Example:

fruits = ["apple", "banana", "cherry"]

for x in fruits:

  print(x)

Code run in vs code: