Two practical skills for Python and two practical skills for python

Source: Internet
Author: User

Two practical skills for Python and two practical skills for python

This article records two common practical skills for beginners of Python and shares them with you for your reference. The details are as follows:

1. variable parameters

The sample code is as follows:

>>> def powersum(power, *args): ...   '''''Return the sum of each argument raised to specified power.''' ...   total = 0 ...   for i in args: ...     total += pow(i, power) ...   return total ...>>> powersum(2, 3, 4) 25>>> powersum(2, 10) 100

Because there is a * prefix before The args variable, all redundant function parameters are stored as a tuple in args. If the prefix is **, redundant parameters are considered as Dictionary key/value pairs.

The 2.exe c statement treats str as a valid Python code for execution.Execfile (filename [, globals [, locals]) function can be used to execute a file.

The sample code is as follows:

>>> exec 'print "Hello World"' Hello World>>> execfile(r'c:\test.py') hello,world!

I hope this article will help you with Python programming.


Python for beginners

Hello, please let me answer your question. If you are new to Pyhon, we suggest you start with 2. x.

I started learning PYTHON this summer. I had a book that made me start very fast.
The score for "Python basics tutorial" is 8.2. The address is as follows:
Book.douban.com/subject/4866934/

It is very suitable for beginners. It is not only suitable for beginners who are familiar with PYTHON for the first time, but also suitable for later use as a tool book.
After introducing the basic features, network programming, file operations, xml/html, pygame (game), image processing, and so on will all be involved, so it is very suitable for beginners to have a comprehensive understanding of python, and finally there are many practical projects, let you feel the mysteries of python.

After reading this book carefully for a month, you may find it sufficient.
We recommend the next book "Python learning manual", which is rated as 8.4. The address is as follows:
Book.douban.com/subject/3948354/

Hope we can learn python together! At the same time, the python Group wishes you a pleasant programming!

Simple questions for beginners of python

My solution is to copy the chm File in windows. Or download it. Then there are many tools in ubuntu to view CHM. That's what I did.

Help () is not easy to use.

Everything in python is an object, and it is not completely correct. Mostly.
For example, print dir (1)

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.