History of Python programmers and history of python programmers

Source: Internet
Author: User

History of Python programmers and history of python programmers

Factorial algorithm code written by various programmers

#-*-Coding: UTF-8 -*-

# New Programmer (recursion)

Def factorial (x ):

If x = 0:

Return 1

Else:

Return x * factorial (x-1)

Print factorial (6)

# Programmers with one year of Python experience

Def Factorial (x ):

Res = 1

For I in xrange (2, x + 1 ):

Res * = I

Return res

Print Factorial (6)

# A lazy Python programmer

Def fact (x ):

Return x> 1 and x * fact (x-1) or 1

Print fact (6)

# More lazy Python programmers

F = lambda x: x and x * f (x-1) or 1

Print f (6)

# Expert Python programmers

Import operator as op

Import functional as f

Fact = lambda x: f. foldl (op. mul, 1, xrange (2, x + 1 ))

Print fact (6)

# Python hacker

Import sys

Def fact (x, acc = 1 ):

If x: return fact (x. _ sub _ (1), acc. mul _ (x ))

Return acc

Sys. stdout. write (str (fact (6) + '\ n ')

# Expert programmers

Imort c_math

Fact = c_math.fact

Print fact (6)

# Programmers with one year of C experience

Def fact (x ):

Result = I = 1;

While (I <= x ):

Result * = I;

I + = 1;

Return result;

Print (fact (6 ))

 

I am a beginner in Python. I found this article interesting on the Internet, so I want to rewrite it in my blog.

On the one hand, you can improve your Python level, and you can also learn and share with more Python enthusiasts.

I use Python QAQ

Here is a more complete original address: http://python.jobbole.com/15005/

 

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.