0

How to add block of code in python?

In c and cpp we have braces to add block of the code inside a function. Example: int func() { //created block inside function { Int I; } return 0; } How do we achieve same in python? Any idea?

23rd Jun 2020, 6:38 PM
$±𝐎â‚č𝔭!𝐹𝓝
$±𝐎â‚č𝔭!𝐹𝓝 - avatar
5 Respostas
+ 1
Ah okay. Yeah, anonymous scopes can't be made, it has to be a function, class, container or whatever.
28th Jun 2020, 10:17 AM
HonFu
HonFu - avatar
+ 3
Python is based on indentation That's mean tabs for example This is in C++: int add(int a, int b) { return a+b; } In C++ spaces(tabs) is optional This is in python: def add(a,b) : return a+b The tab in the second line after colon is compulsory
23rd Jun 2020, 6:51 PM
ycsvenom
ycsvenom - avatar
+ 2
If you want a comprehensive description of blocking in Python: https://code.sololearn.com/cT5BRIbkia21/?ref=app
23rd Jun 2020, 8:44 PM
HonFu
HonFu - avatar
+ 1
I just want to create nested block like below. int func() { //1 st block //created block inside function { // block Int I; } return 0; } Please don't suggest nested function.
25th Jun 2020, 4:42 PM
$±𝐎â‚č𝔭!𝐹𝓝
$±𝐎â‚č𝔭!𝐹𝓝 - avatar
+ 1
It is not possible in python. Got the answer from Oma Falk.
28th Jun 2020, 10:11 AM
$±𝐎â‚č𝔭!𝐹𝓝
$±𝐎â‚č𝔭!𝐹𝓝 - avatar