首页 > 编程语言 >实验1 Python开发环境使用和编程初体验

实验1 Python开发环境使用和编程初体验

时间:2023-03-09 13:57:08浏览次数:41  
标签:初体验 format Python x1 编程 x2 y1 print y2

实验任务1

task1-1

Python源码

1 print('hey,u')
2 print('hey', 'u')
3 x,y,z = 1,2,3
4 print(x,y,z)
 1 x,y,z = 1,2,3
 2 print('x = %d, y = %d, z = %d' %(x,y,z))
 3 print('x = {}, y = {}, z = {}'.format(x,y,z))
 4 print(f'x = {x}, y = {y}, z = {z}')
 5 
 6 
 7 print(x)
 8 print(y)
 9 print(z)
10 
11 
12 print(x, end=' ')
13 print(y, end=' ')
14 print(z)

 

运行截图

 

task1-2

 1 x1, y1 = 1.2, 3.57
 2 x2, y2 = 2.26, 8.7
 3 
 4 print('{:-^40}'.format('输出1'))
 5 print('x1 = {}, y1 = {}'.format(x1, y1))
 6 print('x2 = {}, y2 = {}'.format(x2, y2))
 7 
 8 
 9 print('{:-^40}'.format('输出2'))
10 print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1))
11 print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2))
12 
13 
14 print('{:-^40}'.format('输出3'))
15 print('x1 = {:<15.1f}, y1 = {:<15.1f}'.format(x1, y1))
16 print('x2 = {:<15.1f}, y2 = {:<15.1f}'.format(x2, y2))
17 
18 
19 print('{:-^40}'.format('输出4'))
20 print('x1 = {:>15.1f}, y1 = {:>15.1f}'.format(x1, y1))
21 print('x2 = {:>15.1f}, y2 = {:>15.1f}'.format(x2, y2))
View Code

 

task1-3

1 name1, age1 = 'Bill', 19
2 name2, age2 = 'Helle', 18
3 title = 'Personnel Information'
4 
5 print(f'{title:^40}')
6 print(f'name:{name1:10} age" {age1:3}')
7 print(f'name:{name2:10} age" {age2:3}')
8 print(40*'=')
View Code

 

 

实验总结

print()的常用的几种输出方式:1.用于输出单个字符串或单个变量print(' ')。2.用于输出多个数据项,用逗号隔开print(' ', ' ')

 

 

实验任务2

标签:初体验,format,Python,x1,编程,x2,y1,print,y2
From: https://www.cnblogs.com/202280060019x/p/17191453.html

相关文章

  • python+playwright 学习-27 鼠标悬停 hover() 和listitem 定位
    前言鼠标悬停到某个元素上后出现一些选项,这是很常见的操作了,playwright操作鼠标悬停非常简单,只需调用hover()方法。鼠标悬停打开官网https://playwright.dev/鼠标悬......
  • OpenAI/ChatGPT的Python API,关于os.getenv()环境变量设置问题。
    OpenAI官方的pythonapi连接示例中有一行代码openai.api_key=os.getenv("OPENAI_API_KEY")其中的os.getenv()是从环境中获取环境变量,上面代码要获取的就是OP......
  • 使用Python实现简易版Netcat
    NetcatNetcat是一种网络工具,也称为“nc”,可用于在计算机网络之间进行TCP/IP或UDP连接。它可以用于连接到其他计算机上的端口,发送和接收数据,扫描端口以及创建服务器等。使......
  • 实验1 Python开发环境使用和编程初体验
    task1_1:1.print('hey,u')print('hey','u')x,y,z=1,2,3print(x,y,z)print('x=%d,y=%d,z=%d'%(x,y,z))print('x={},y={},z={}'.format(x,y,z))print(f'x={x},y=......
  • Python列表(list)
    Python 列表(List)序列是Python中最基本的数据结构。序列中的每个元素都分配一个数字-它的位置,或索引,第一个索引是0,第二个索引是1,依此类推。Python有6个序列的内置类......
  • Python单例模式
    单例模式(SingletonPattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在。当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上......
  • python连接mysql
    conn=pymysql.connect(host="127.0.0.1",port=3306,user="root",password="root",database="mydatabase",charset="utf8")cur=conn.cursor(cursor=pymysql.cursor......
  • Python基本语法 -- 变量、运算、字符串
    对象要存储一个对象需要包括id(标识,对象一旦创建id永不改变,在内存中的位置)、type(类型,当前对象的类型,决定其功能)和value(值,存储的具体值)根据其值能否更改进行分类,可分为可......
  • python+playwright 学习-26 locator.filter()过滤定位器
    前言locator.filter()方法可以对locator定位到的元素进行筛选过滤,可以按文本过滤,也可以按locator定位器过滤。locator.filter()文本过滤考虑以下DOM结构,我们要在其......
  • Python学习日志
    面对if语句,python和java和C不同的是,python更多的是if条件1语句:内容elif条件2语句:内容else:内容 #上面所有条件都不满足,则运行该条件语句下的。 0A=int(input()......