About 263,000 results
Open links in new tab
  1. What are blocks of code in Python? The definitions are all …

    Apr 29, 2018 · A block is just a concept and you can't see it like as function. A block is the structure of code to separate part of the code from another part of the code. A function is a block, and classes are blocks and self consist of many blocks inside.

  2. How to organize Python code into collapsable / expandable chunks?

    Jul 11, 2019 · A “code cell” is a block of lines to be executed all at once in the integrated Python console. You can define cells simply by adding inline comments #%% to your regular Python files. PyCharm detects these comments and shows you a special run icon in the left gutter.

  3. How to comment out a block of code in Python [duplicate]

    Python does not have such a mechanism. Prepend a # to each line to block comment. For more information see PEP 8. Most Python IDEs support a mechanism to do the block-commenting-with-hash-signs automatically for you. For example, in IDLE on my machine, it's Alt+3 and Alt+4.

  4. Deactivate code in python without changing indentation or adding ...

    Jan 29, 2016 · Move the code to a new function in a new module. Create a second module which contains the same function but empty. Switch between the two modules in import; Create a config flag and protect the code with an if. That way, you have a single place in your config to enable/disable the code. Move all your code into a class.

  5. Is there a shortcut to comment multiple lines in python using VS …

    Sep 26, 2022 · All you need to do is select that code block with your mouse, then press the following key combination: Ctrl + K then press Ctrl + C if you’re using Windows Command + K then press Command + C if you’re on a Mac. You can also use: Ctrl + / to comment and uncomment lines of Python code on Windows.

  6. Block scope in Python - Stack Overflow

    The idiomatic way in Python is to keep your functions short. If you think you need this, refactor your code! :) Python creates a new scope for each module, class, function, generator expression, dict comprehension, set comprehension and in Python 3.x also for each list comprehension. Apart from these, there are no nested scopes inside of functions.

  7. How do I unindent blocks of code in Python? - Stack Overflow

    I am using Python 2.7.10 and am having trouble trying to unindent a block of code. Surely there is some sort of shortcut, instead of having to backspace every individual line? From the Python Shell, I opened a new file (.py) and that's where I am writing the code. Shift + Tab does not work.

  8. How can I comment multiple lines in Visual Studio Code?

    This is probably not the top voted answer because of how VS Code works for different languages. For python code, the "comment block" command Alt + Shift + A actually wraps the selected text in a multiline string, whereas Ctrl + / is the way to toggle any type of comment (including a "block" comment as asked here). –

  9. How do I create multiline comments in Python? - Stack Overflow

    Apr 9, 2022 · For commenting out multiple lines of code in Python is to simply use a # single-line comment on every line: # This is comment 1 # This is comment 2 # This is comment 3 For writing “proper” multi-line comments in Python is to use multi-line strings with the """ syntax Python has the documentation strings (or docstrings) feature.

  10. How can I time a code segment for testing performance with …

    $ python -mtimeit "all(True for _ in range(1000))" 2000 loops, best of 5: 161 usec per loop $ python -mtimeit "all([True for _ in range(1000)])" 2000 loops, best of 5: 116 usec per loop Run with -h to see all options. Python MOTW has a great section on timeit that shows how to run modules via import and multiline code strings from the command line.

Refresh