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.

Advertisements
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 raw_input() error in Visual Studio Code_Python Learning

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 raw_input() error. If you cannot run the python code in Visual Studio Code totally, this article may be not useful to help you with.

To solve the problem is very easy:

  1. Keep on the editor’s UI and just save the .py file to your disk.
  2. Right click the editor’s UI and click the menu Run Python File in Terminal.
  3. Now you can get the Terminal on the bottom of the Visual Studio Code.
  4. Enjoy it!