The main function is the entry point of your program, it’s the first function that gets executed when you run the script. In a script, you can have many functions but the main function is the one that gets executed first.
Tag: python basic concepts
Python | What does the if __name__ == “__main__”: do?
In Python, the if __name__ == “__main__” idiom is a guard statement that is used to determine whether the code in the block following it is being run as the main program or being imported as a module into another program.
When a Python script is run, the interpreter assigns the special variable __name__ the value “__main__”.
Python | Variables
In Python, a variable is a named location in memory where a value can be stored. Variables are used to store data values and can be used to refer to those values throughout your program. As python is Dynamically typed programming language, So We don’t need to mention the data type of the variables during its creation.
Python | print() function
In Python, the print() function is used to display text on the screen. It can be used to print text, variables, and the results of mathematical operations.
Python | Comments
In Python, Comments are used to explain or document code. They are ignored by the interpreter and do not affect the execution of the program.
There are two types of comment in Python:
1) single-line comments
2) multi-line comments
Python | what is Indentation?
In Python, indentation is used to indicate the structure of a program and to define blocks of code. Unlike many other programming languages, Python uses indentation to indicate the level of nested code blocks, rather than using curly braces or other special characters.
Python | break, continue, and pass keywords
In Python, break, continue, and pass are keywords that are used to control the flow of a program.
Here’s a brief explanation of each one, along with examples …
Python | range() function
The range() function in Python is used to generate a sequence of numbers. It can take atleast one (stop) and atmost 3 arguments: start, stop, and step.
Python | loops
In Python, loops are used to repeatedly execute a block of code. There are two main types of loops: for loops and while loops.
Python | Conditional Statements
In Python, conditional statements are used to control the flow of a program based on certain conditions. They allow you to check for certain conditions, and then execute code depending on whether or not those conditions are met. The most commonly used conditional statements in Python are if, elif, and else.