Python learns the 4th day basic syntax-variables, data types

Source: Internet
Author: User

Mainly refer to http://www.cnblogs.com/yanxy/archive/2010/02/22/ILovePython.html, record their own experience.

One, variable

1. Dynamic type/strong type

Dynamic type: Some Like JS, a variable can be assigned to a number, and then assign to the string, no effect.

Strong type: i = 10; j = ' ss ', if you want to i+j, will error, and JS can be like this

2. Boolean type

And JS somewhat similar, 0, empty, empty array these all count as false

3. Quotation marks

And JS, single quotation marks can be double quotes, more than a three-quote, similar to the C # @ "", this is convenient. JS does not have this, meet to change line will keep "" + ", although the carriage return will be automatically processed, but still not cool enough

===============

Check, JS also has some processing methods:

var a = "fffffffffffffffffffffffffffffffffffff"; Console.log (a)

This is just for the convenience of writing, front and back is connected, the result is a row of f, and can not be more empty line

Ignorant, did not expect JS also can ... With ' This symbol can, that is, the keyboard ESC under the key, the number 1 to the left, the same as the C # @ "", is the serious line.

4, Unicode: If set to UTF-8, you can add u, if it is ANSI, then it will be wrong to write

VS, set to UTF-8 to run

Open With notepad++, is also set to UTF-8 can, with ANSI directly support Chinese, plus u instead of error

5, Array: Support type mix, try JS also can, array length variable

arr = [' A ', 2, 3]

Arrays and strings are available in this "slicing" way, some like substring or substr

6, meta-group

using () definition, the other is almost (said to be faster), that is, there is only one element followed by a comma, such as Test = [0,]

7. Collection

The syntax for a common collection is: s = set ([' A ', ' B ', ' C '). However, the set has changed a lot in Python 3.0, and the syntax for creating a collection has become: s = {dict}, using the curly bracket method, similar to the one mentioned below. If you pass in a repeating element in set, the collection will automatically merge it. This feature is very useful, such as removing a large number of repeating elements in the list, using set to solve the high efficiency

8, dictionary, is a hash table of key-value pairs

In the end, it is not summed up, copy other people's Bar

(1) Python is a dynamic, strongly typed language that does not have to define its type until it is used, but must be declared and initialized, (2) "All naming is a reference", where the variable name is a reference to the object, and the same variable name can represent different types of data at different stages of the program's Run; (3) " All data is the object ", Python all data types are objects, (compared to C #) have a consistent use of methods; (4)" Think of the problem a bit easier ", Python's numeric types can be said to be only two: shaping and floating point, forget all the numeric types in C # bar; (5) Note that distinguishing between STR and unicode,python string types can sometimes make people dizzy, try to get used to it, and don't forget to "slice" the good tool. (6) Use the list, tuple, set, and dict as "very python" data types, which are defined by [], (), ([]), and {}, respectively.

Python learns the 4th day basic syntax-variables, data types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.