Basic Structure:
Output:
Get confused ? don’t worry about the code if you don’t understand what is going there. Just observe the code and it’s
structure closely.
⚫ Does it have any primary function like C/C++/Java?
⚫ Does it end with ";"?
⚫ Does it have any brackets ?
⚫ Does the variables has any predefined data types?
No, for sake of simplify, We don’t need any main function in a python file. We can start coding
directly just like plug & play (Create file & code).
Also, notice that python don’t have any ending notation at each line like C or Java. We don’t need
to put any special character to mark it as end of command/instruction/statement. Python look for
“Enter”(keyboard enter key pressed) as a mark of end of command/instruction/statement. That
means, every command/instruction/statement ends with “Enter”
Python don’t use any brackets for loops and conditional statements/commands. Instead of
brackets, python use indentation(keyboard tab key pressed). That’s mean we need to use indentation
those places where we used to use brackets in C or java.
Python is so smart that he doesn’t need any declaration for data types. Just make a variable and
assign any data(string, integer, float, boolean) you want to set.
That’s it you have now get the basic of basic idea about python file structure. Now, let’s jump into
deeper structure. Don’t worry I am here, I Will explain everything line by line like ChatGpt (Actually
better that him :D)
This how we will write actual code later. Isn’t it easier than Java and C ? of course it is. We are creating
class, objects constructors, user defined function and main function in a same file with this little code !
Once again notice the indentation again.