码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • [Python] Basic Functions


    Python print() Function

    print(object(s), sep=separator, end=end, file=file, flush=flush)

    It takes one or more arguments separated by comma(,) and adds a 'newline' at the end by default.

    Parameters:

    • object(s) - As many as you want data to display, will first converted into string and printed to the console.
    • sep - Separates the objects by a separator passed, default value = " ".
    • end - Ends a line with a newline character
    • file - a file object with write method, default value = sys.stdout
    1. # Displaying a string
    2. print("Hello, World!")
    3. # Displaying multiple values
    4. name = "Aman"
    5. age = 21
    6. print("Name:", name, "Age:", age)
    7. # Printing variables and literals
    8. x = 5
    9. y = 7
    10. print("x =", x, "y =", y, "Sum =", x + y)
    11. # Printing with formatting
    12. percentage = 85.75
    13. print("Score: {:.2f}%".format(percentage))
    1. Hello, World!
    2. Name: Aman Age: 21
    3. X = 5 y = 7 Sum = 12
    4. Score: 85.75%

    Python Conditional Statements

    Python provides if and else keywords to set up logical conditions. The elif keyword is also used as a conditional statement.

    1. x = 10
    2. y = 5
    3. if x > y:
    4. print("x is greater than y")
    5. else:
    6. print("y is greater than or equal to x")
    x is greater than y

    Python Loops

    1. fruits = ["apple", "banana", "cherry"]
    2. for x in fruits:
    3. print(x, end=" ")
    apple banana cherry
    1. i = 1
    2. while i<5:
    3. print(i, end=" ")
    4. i += 1
    1 2 3 4

  • 相关阅读:
    Java自定义异常类详解及示例
    java毕业生设计在线玩具租赁系统计算机源码+系统+mysql+调试部署+lw
    测试老鸟总结,Allure测试报告-自动化测试详解,惊险避坑...
    全新升级的AOP框架Dora.Interception[6]: 框架设计和实现原理
    数据血缘分析-Python代码的智能解析
    MySQL (十四) 两阶段提交
    Python学习笔记五之错误与异常处理、面向对象实例
    Java | UDP协议
    linux,从零安装mysql 8.0.30 ,并且更新至mysql 8.0.36
    HTML-注册页面
  • 原文地址:https://blog.csdn.net/m0_74331272/article/details/136175323
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号