. Python Help

Source: Internet
Author: User

1. Learn how to view Python Help

(1) When we want to see which data type the python variable belongs to, we can use the

Print (Type (varible))


(2) When we want to see what the specific methods of a variable are

varible = Dict (a=1, b=2)

Print (dir (varible))

This shows all the methods of the variable.


(3) After knowing the method, the concrete method will not use what to do?

Help (sorted ())

Or

You can also view usage by pressing Ctrl + left mouse button.



2. Conversion of the Python variable type

As an example,

Age = 100

Print (' My age was ' + age)

Error after execution of the above code


Because age is an integral type (int), it is printed as a string (str) type

Therefore, the type conversion is done before printing:


Age = 100

Print (' My age was ' + str (age))

So the output is normal.


the int () str () dict () list () tuple () is generally a conversion of these types


A = [1, 2, 3, 4, 5]

Print (dir (a)) View method


This article is from the "Note space" blog, so be sure to keep this source http://286577399.blog.51cto.com/10467610/1975821

. Python Help

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.