INT104 Python Basic Grammar

INT104

Python Basic Grammar

  • Creart a comment

    	#this is a comment.
    
  • Multiline comments

    """
    This is a comment written in
    more than one line
    """
    
    • print() function
    print("Hello World")
    print("Hello", "how are you?")
    x = ("apple", "banana", "cherry")
    print(x)
    
  • Variables

    x=4     #x is of type int
    x="Sally" #x is now of type str
    #If you want to specify the data type of a variable 
    #this can be done with casting 
    x = str(3) # x will be '3'
    y = int(3) # y will be 3
    z = float(3) # z will be 3.0
    x, y, z = "Orange", "Banana", "Cherry"
    #If you have a collection of values in a list, tuple etc.
    #Python allows you to extract the values into variables.
    #This is called unpacking
    fruits = ["apple", "banana", "cherry"]
    x, y, z = fruits
    
  • Data types
    在这里插入图片描述

    If you want to specify the data type, you can use the following constructorfunctions:
    在这里插入图片描述

  • Operators

    • Arithmetic operators(算数运算符)

      # 基本和Java一样
      #** Exponentiation 求幂
      x**y
      #// Floor division 整除
      x//y #5//2=2
      
    • Assignment operators(赋值运算符)

      • Assignment operators are used to assign values to variables:
        在这里插入图片描述
    • Comparison operators(比较运算符)

      • 和Java一样
    • Logical operators(逻辑运算符)

      #and
      x<5 and x>10
      #or
      x<5 or x>10
      #not
      not(x<5 and x<10)
      
    • Identity operat

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值