Beginner : Simple Python test

#!/usr/local/bin/python
# -*- coding: utf-8 -*-.
# line of utf-8 is for multi-language
# optional 4-spaces before line rule for Python.

import sys
sys.path.append("/homes/sli/pexpect-2.3/")
import pexpect
import time
import re
import os

print "Welcome to Python!"
def sum(x,y):
    sum = x+ y
    total = ‘the sum of {} and {} is {}.‘ .format(x,y,sum)
    print total
sum(2,3)
sum(-99,200)

[tool01 ~/my-test]$ ./sum-1.py
Welcome to Python!
the sum of 2 and 3 is 5.
the sum of -99 and 200 is 101.
[tool01 ~/my-test]$

时间: 2024-10-10 14:37:11

Beginner : Simple Python test的相关文章

46 Simple Python Exercises (前20道题)

46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises constructed (but in many cases only found and collected) by Torbj?rn Lager ([email protected]). Most of them involve characters, words and phrases, rather than

46 Simple Python Exercises 16-22题

会贴出原题和答案,答案不是最优的,也反映了我的学习过程,如果有时间会更新优化的代码. Write a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n. #Write a function filter_long_words() that takes a list of words # and a

Simple Python Dictionary :)

摘自 http://github.com/panweizeng/home/blob/master/code/python/dict/dict.py 支持简单的Ch to En 和En to Ch我把它放在 /usr/bin/dict 1234567891011 $ dict 白痴 单词:白痴 音标: bái chī 释义:idiot idiocy 例句:他很聪明,但有时举止像是白痴. 翻译:He is intelligent, but sometimes he behaves like an i

46 Simple Python Exercises-Higher order functions and list comprehensions

26. Using the higher order function reduce(), write a function max_in_list() that takes a list of numbers and returns the largest one. Then ask yourself: why define and call a new function, when I can just as well call the reduce() function directly?

46 Simple Python Exercises-Very simple exercises

4.Write a function that takes a character (i.e. a string of length 1) and returns True if it is a vowel, False otherwise. def if_vowel(a): a=a.lower() if a in('a','e','i','o','u'): return True else: return Falseprint(if_vowel('A')) 原文地址:https://www.c

Python著名的lib和开发框架(均为转载)

第一,https://github.com/vinta/awesome-python Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Inspired by awesome-php. Awesome Python Admin Panels Algorithms and Design Patterns Anti-spam Asset Management A

Python框架、库以及软件资源汇总

转自:http://developer.51cto.com/art/201507/483510.htm 很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世界各地的程序员们都能够贡献他们的代码与创新. Python就是这样一门受到全世界各地开源社区支持的语言.Python可以用来开发各种小工具软件.web应用.科学计算.数据分析等等,Python拥有大量的流行框架,比如Django.使用Python框架时,可以根据自己的需求插入不同的模块,比如可以用S

python 装饰器语法糖(@classmethod @staticmethod @property @name.)原理剖析和运用场景

引用:http://blog.csdn.net/slvher/article/details/42497781 这篇文章系统的介绍这几者之间的关系和区别.有兴趣的朋友可以到上面的链接查看原文,这里我把原文拷贝如下(如有侵权,通知马上删除) ==================================================================== 在阅读一些开源Python库的源码时,经常会看到在某个类的成员函数前,有类似于@staticmethod或@classme

Machine and Deep Learning with Python

Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstitions cheat sheet Introduction to Deep Learning with Python How to implement a neural network How to build and run your first deep learning network Neur