"Python" Java Programmer learning Python (iv)-built-in methods and built-in variables

Source: Internet
Author: User

"If Love has Providence"

When the sky that star appears, you know I began to miss, how much love can only distant across, like moonlight spilled to the sea, young we thought, love people can to forever, when we believe that the feelings to the depths together, hear not the sigh of the wind, who know what Love is, a short encounter but the obsession, exhausted the time of life, Unexpectedly learn will not forget, now we have apart, life like people around me, the eyes of people to give me the most trust of the dependence, I hope you are gentle treatment, how many trance, as if to see you in the crowd of rivers, vaguely you have surfaced, a blink of an eye, a short encounter but forget, how many trance time, As if to see you in the crowd of rivers, vaguely you have surfaced, a blink of an eye and disappear, when the sky that star appeared, you know I began to miss, how many love this life nowhere to place, what has changed, moonlight like Spring breeze.

A song that most wants to hear and dare not listen to.

First, Python's global function

Global functions This is compared with JS, it is very convenient to use, do not need to introduce additional modules, directly can use its methods.

Second, the overall method of the detailed

Python's global approach has many, see the official website document: https://docs.python.org/3/library/functions.html. Some methods used very frequently, need to remember the usage, some methods are not often used, there is a general impression on it, wait until you want to use the time to find, not to re-implement, the following is a list of global functions:

Global functions
abs():求绝对值
dict():创建字典对象 help():调用内置帮助系统 min():求最小值 setattr():设置对象某个属性的值
all () : Determines whether null or all elements are true dir () : Returns the list of objects hex () : Integer to 16 binary string next () : Returns the next element of an iterator slice () : Returns a Slice object
any (): Determine if an element is true divmod (): Divisor id (): Returns the identity of the object object (): Returns a new non-feature object sorted (): Sort
ASCII (): Returns the escaped string enumerate (): Returns an enumeration object input (): Get input oct (): integer to octal string staticmethod (): Returns a static method of function
bin (): integer to binary string eval (): Code Execution int (): string to int open (): Open a file STR (): Returns the STR version of object
bool (): Returns a Boolean value exec (): Dynamically execute Python code isinstance (): Determines whether the specified type ord (): Word representable Unicode sum (): Summation
bytearray (): Returns a new byte array filter (): Filter element issubclass (): Determine if it is its subclass pow (): Several times for a number of parties super (): Returns a proxy object
bytes (): Returns a Byte object float (): string conversion float iter (): Returns an Iterator object print (): Print tuple (): Returns a tuple
callable (): Determine if it is callable format (): Formatting len (): Return object Length (number of elements) property (): Returns a property attribute type (): Returns the type of object
CHR (): Returns a Unicode-represented string frozenset (): Return Frozenset object list (): Back to list range (): Return interval vars (): Returns the __dict__ property of an object
classmethod () : Wrapping a function into a class method getattr () : Gets the value of the specified property of the object locals () : Update and return the current local symbol table's dict repr (): Return object string represents zip () : Create an iterator
compile (): Compiling code objects globals (): Returns the dict of the global symbol map (): Specifies the method for applying iterators to each object reversed () : Returns a reverse iterator __ IMPORT__ (): Not recommended method
complex():解析复数 hasattr():判断对象是否有属性 max():求最大值 round():返回一个浮点型 近似值
delattr():删除对应属性 hash():返回对象的hash值 memoryview():返回给定参数的“内存视图” set():返回一个新的set 对象

First, we are familiar with some of the most common.

2.1 Print ()

This method can be said to be most commonly used, and Java SYSTEM.OUT.PRINTLN () as classic, used in the console to print output, of course, the actual production of the use of the log frame.

Print (A) Print ('abc') Print ('hello','World')

Console output:

Abchello World

Used to display the results immediately to the person to see the drop.

2.2 Input ()

This method I think should be defined as a beginner method, used in the request user input data, beginners a language when used more, the actual production of the basic use, the necessary variables will basically read the configuration file:

Name=input (); Print ('hello', name)

Run time will stop, waiting for user input, input Yiwangzhibujian, will print out the Hello statement, console input and output as follows:

Yiwangzhibujianhello Yiwangzhibujian

Note: input receives a string, even if the input is 1, if a number is required to be converted.

2.3 Int ()/float ()

These two methods also use more, that is, the conversion of strings to integer or floating-point method.

Num=int ('ten')print(num+1)

The addition of strings and numbers will result in an error, so conversion is required.

2.4 isinstance ()

This method is more used when defining a method, because Python does not specify a type when defining a variable, but using the wrong type will result in an error, so you can use this method to determine the type of the variable:

x=123isnum=isinstance (x, int)print(isnum)

If you want to define a strong function, you still need to use this method a lot.

2.5 len ()

This method is used to return the number of elements of an object, or the number of elements in the collection, and the documentation is clearly explained.

or or or frozen set).

The most commonly used has been introduced, the other global methods can be familiar with, and so on when used to check the detailed definition is also possible.

Third, global variables

There are also global variables in Python. There is no contact now and the follow-up will be added.

"Python" Java Programmer learning Python (iv)-built-in methods and built-in variables

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.