wwfl.net
当前位置:首页 >> python 取负数 >>

python 取负数

直接int(..)或float(...)就好啦 [willie@bogon zhidao]$ python3 Python 3.5.2 (default, Sep 30 2016, 01:32:24) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux Type "help", "copyright", "credits" or "license" for more information. ...

#!/usr/bin/python# -*- coding:utf-8 -*-# @Time : 2018/6/15 5:55# @File : test.py"""这是一个测试脚本"""def myremove(alist): alen = len(alist) olist = [] for i in range(alen): temp = alist[i] if not isinstance(temp, (int, float))...

-5 // 3

apple pie^ 下标0 ^ 下标-3从下标-3向右找不到下标0,所以是空字串,如果是food[-3:]就是'pie',因为不指定范围的结束就等于在遇到最后一个字符之后结束 -3是p,0是开始,这是规定的

number = int(input('Please input a number: '))# print( number)if number >= 0: print( number)else: print( -number)

来个简单的,for循环,弄个if,判断大于0和小于0,并做计数, 比如: s = [1,5,-7]counter = 0for i in s: if i > 0: counter += 1print counter

a=(-90)if a>=0: #不成立 print(a)else: print(-a) #输出-a即90

用int()那个不叫系统崩溃,叫“未处理的意外”,try/except就是干这个的。def func(x): try: x=int(x) return isinstance(x,int) except ValueError: return Falsefunc(1)Truefunc('1.1')Falsefunc('-1')Truefunc('-1.1')Falsefunc('asdf')False

a=int(input()) if a>0: print('正数') elif a<0: print('负数') else: print('0')

没看明白你这个例子。给出明确的输入和输出(包括其类型,最好贴python代码)

网站首页 | 网站地图
All rights reserved Powered by www.wwfl.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com