Python print打印
1、Python运算符:
+:加
-:减
*:乘
/:除以
%:去除法后的余数
//:取整除
2、字符串center方法:
a='111'
print(a.center(4,'2')) #让字符串占位 4个位置,剩余的位置用‘2’填充,默认为空格 执行结果:
1112 3、打印三角形:

1.首先是空格符,根据对图形的观察可以得到 空格符数量 和 行号 的关系:
当前行号 当前行空格符数量
1 7
2 6
3 5
4 4
5 3
6 2
.... ....
由此得出公式:当前空格符数量 = 最大行号 - 当前行号
2.接下来是*符号的个数,同样根据对图形的观察可以得到 *符号数量 和 行号 的关系:
当前行号 当前行*符数量
1 1
2 3
3 5
4 7
5 9
6 11
由此得出公式:当前*符数量 = 当前行号 * 2 - 1
n=6
for i in range(0, n+1): #打印正三角形
print(('*' * (i * 2 - 1)).center(n*2-1)) #星号个数: 当前行号乘以2-1 for i in range(0,n+1): #打印倒三角形
print(('*' * (n + 1 - i) * 2).center(n*2-1)) #星号个数: 倒三角 最大行号 减去 当前行号 for i in range(0,n+1): #打印直角三角形 #星号个数:组行减少
print('*'*i)
4.打印乘法表
for i in range(1,10,1):
for j in range(1,i+1):
print("%d*%d=%2d"% (i,j,i*j),end="\t") print("\n")
面试题汇总:
输入IP转成int
ip=input('输入IP>>>>>')
ip_list=ip.split('.')
int_ip_list=[ int(n) for n in ip_list if int(n)<255]
print(int_ip_list)
2个有序列表合并
#!/usr/bin/python
# -*- coding: utf-8 -*-
list1 = [3, 7, 8, 9, 12]
list2 = [5, 6, 10, 13, 25, 30]
result = [] while list1 and list2:
if list1[0] < list2[0]:
result.append(list1[0])
list1.remove(list1[0])
else:
result.append(list2[0])
list2.remove(list2[0]) #list1元素已全部添加到result,此时只需将剩余的元素添加到result中
for i in list2:
result.append(i)
print(result)
1个无序列表排序
#冒泡排序法: #冒泡核心:总是拿第1个(目前老大),和其他所有 PK 得出新老大, l=[3,2,1,5,9] count=len(l) for i in range(0,count):
print(l)
for j in range(i+1,count):
if l[i] > l[j]:
l[i],l[j]=l[j],l[i] else:
print(l)
求 1个超大型列表中的元素 前10位
l=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
new_l=[] #开辟1个新列表
for i in l:
new_l.append(i) #在新列表中添加1个元素
new_l.sort() #排序1次
new_l=new_l[-10:] #获取后10个重新赋值给新列表
https://www.cnblogs.com/suiy-160428/p/5594389.html
Python print打印的更多相关文章
- python print 打印的数据包含中文,打印报错UnicodeDecodeError: 'gbk' codec can't decode bytes in position 459-460: illegal multibyte sequence解决办法
python 2.7 print 的数据中若包括中文,打印则会报错UnicodeDecodeError: 'gbk' codec can't decode bytes in position 459- ...
- 【原创】python中文编码问题深入分析(二):print打印中文异常及显示乱码问题分析与解决
在学习python以及在使用python进行项目开发的过程中,经常会使用print语句打印一些调试信息,这些调试信息中往往会包含中文,如果你使用python版本是python2.7,或许你也会遇到和我 ...
- Python使用print打印时,展示内容不换行
原理 Python的print()函数中参数end='' 默认为\n,所以会自动换行; 默认的print()函数: print(end='\n') 方案 Python 2: 在print语句的末尾加上 ...
- Python学习4——print打印
print(): 在控制台输出变量的值: print打印完后换行: print(123) # 完整模式:print(123,end="\n") 希望打印完不换行: print(1 ...
- 技巧:Python中print打印信息的同时打印文件、行号
import sys def Log(msg): print('Print Message: '+msg+' ,File: "'+__file__+'", Line '+str(s ...
- 将python代码打印成pdf
将python代码打印成pdf,打印出来很丑,完全不能看. mac下:pycharm 编辑器有print的功能,但是会提示: Error: No print service found. 所以需要一个 ...
- python print 在windows上 出现 Bad file descriptor error
先说一下情况,一个python写的采集程序,做成windows服务在windows上运行. 这个问题出现的挺奇特,本来一套采集程序,一个采集文件的时候没问题,两个采集文件的时候也没问题,当三个采集文件 ...
- Python print函数用法,print 格式化输出
原文地址:http://blog.csdn.net/zanfeng/article/details/52164124 使用print输出各型的 字符串 整数 浮点数 出度及精度控制 strHello ...
- python print格式化输出。
python print格式化输出. 1. 打印字符串 print ("His name is %s"%("Aviad")) 效果: 2.打印整数 print ...
随机推荐
- HDU 4496 D-City(逆向并查集)
http://acm.hdu.edu.cn/showproblem.php?pid=4496 题意: 给出n个顶点m条边的图,每次选择一条边删去,求每次删边后的连通块个数. 思路: 离线处理删边,从后 ...
- Java单例设计模式(实现Java的一个类只有一个对象)
单例设计模式的定义:单例设计模式是一种软件设计模式,在它的核心包含一个称为单例类的核心类. 核心便是希望一个类只有一个对象. 如何实现类在内存中只有一个对象呢? 第一步:构造私有:第二步:本身提供一 ...
- C#调用cmd命令
using System.Diagnostics; public class CmdHelper { private static string CmdPath = @"C:\Windows ...
- mutect/mutsig/gistic官网汇总
http://software.broadinstitute.org/software/cprg/
- perl hash array 嵌套 push
$hash{"A"}=["pp"];想变成:$hash{"A"}=["p","q"];因为 $has ...
- hdu 6134 Battlestation Operational 莫比乌斯反演
Battlestation Operational Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- colgroup和col的区别
转载自:http://blog.csdn.net/carefree31441/article/details/3291397 colgroup和col一般出现在表格当中定义表格单独列的任意属性col能 ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\u25aa' in position 15: illegal multibyte sequence
UnicodeEncodeError: 'gbk' codec can't encode character '\u25aa' in position 15: illegal multibyte se ...
- 异常处理.VC++
ZC:个人这样 理解 C++的异常处理: ZC: (1).C++标准异常处理,try{}catch{} 抛异常:throw() [ 据说是包装的Windows函数RaiseException() ] ...
- OpenModelica Debug
assertion只触发一次 The gdb process has not responded to a command within 40 second(s).This could mean it ...