Python syntax to learn a simple arrays, variables, dictionaries

Python really strong! ! !
 Freshman year, when exposed to a little Python, this middle-aged memory had let me forget (remember made a 3D Pinball), in conclusion, that is, only knock against the code book is not going to learn something. After struck again, no practice will be forgotten, if you try to write algorithms in Python recurring theme, grammar you, there is no obstacle.
 Jiedi return to their roots or to practice more.
  • Python encapsulation strong compatibility performance in that its data type (generic). You define an array variable totally do not need to define the type, you can direct assignment. The array contains the following two types, string, integer, can be put together.
tmp=['test',1]
print(tmp)
#result:
['test', 1]
  • Python variables do not need to explicitly declare, in most cases directly in accordance string processing (input are strings), need to be converted themselves into other types. such as:
a=input()
print(int(a))

# 我们输入的都被当作字符串,输出时可以调用int()转换成整数,才可以进行运算。
  • Python dictionary is a good thing, in fact, similar to the array which sets up a hashmap, based on a strong analytical ability, good package to let us directly:
a={
    'a':1,
    'b':2,
    'c':3
}
print(a)
#result
{'a': 1, 'b': 2, 'c': 3}

A dictionary on the web similar to the session, a set of key mappings. Want to take the key values ​​can be key.

  • Python package of good and bad, but fortunately you use the convenient, but too easy to make people feel very strange. Used to write c ++, java code will feel warm Python overdone.
    1. Sometimes their own definition of a variable, read, read, have forgotten its type, is not strong enough sense of logic.
    2. It is not suitable as an introductory language, first learn c it, to learn another language quickly entry (grammar).
    3. write c ++ code is often written naming the same thing can be judged by its scope when looking statements. Python is not specified, direct assignment is not easy to see that this variable is topical? Global use?
Published 50 original articles · won praise 67 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_41033366/article/details/103916383