Posted in Python

A nice way to write List Set in python, just like javascript

While learning js, what impressed me is the writing style of js.

var s = {

}

In Python, there is also fine.

Like:

list= [

[“a”, “b”, “c”],

[1, 2, 3],

[True, Flase]

]

It works fine.

Posted in Python

Some interesting things about Tuple in Python

1.

The contents in Tuple cannot be changed. But if there is something changeable in Tuple, it can be changed.

Example:

t = (“a”, “b”, 1, False, [1, 2, 3])

t[4][0] = 6

print(t)   ### (“a”, “b”, 1, False, [6, 2, 3])

2.

If there is only an element in  tuple, like (1), you should plus a “,” after it, like (1, ). Why?

Because in python, (1) will be recognized as the whole number 1 in maths, so be careful.

Posted in Python, Visual Studio Code

How to solve the input() error in Visual Studio Code when you run the code in the integrated terminal

This article was born some years ago but until lately I found the serious mistake in it. Now I fix it and I’m sure you can make it after you follow the steps. Sorry for those who searched this passage but left with depression.

First of all, you need to run the python code correctly in your Visual Studio Code, just having an annoying problem that you cannot deal with the input() error.

How do you know that? You can install an extension from VS Code Store named code runner(by Jun Han), and you will get a new right-click menu named Run Code in VS Code so that you can run the code in the integrated terminal of VS Code.

If you cannot run the python code in Visual Studio Code totally, this article may be not useful to help you with. You should check your environment, such as reinstall Python or VS Code.

Code runner is a very nice debug tool but it is read-only in the terminal so that you cannot deal with input().

To solve the problem is very easy:

  1. Install an extension named Python(by Microsoft) and you will get a new right-click menu in your editor.
  2. Keep on the editor’s UI and just save the .py file into your disk.
  3. Right click the editor’s UI and click the menu Run Python File in Terminal.
  4. Now you can get the Terminal on the bottom of the Visual Studio Code and you can input anything you want.
  5. Enjoy it!

Well, this solution is made for debugging in the integrated terminal. If you would like to save the file and run it in CMD or Powershell, that’s fine.