LogoLogo
  • V by Example
  • en
    • examples
      • section_3
        • Functions
        • Methods
        • Arrays
        • Struct
      • section_1
        • Primitives
        • Keywords
        • Variables
        • Formatted Print
        • Strings
        • Comments
      • section_4
        • Files
        • JSON
        • Testing
        • Array Functions
      • section_2
        • Operators
        • Looping Constructs
        • If statement
        • Match
  • V por exemplos
    • Contribuindo
    • examples
      • section_1
        • Comentários
        • Primitivos
        • Palavras-chave
      • section_2
        • Operadores
  • V mit einem Beispiel
    • examples
      • section_3
        • Methods
        • Struct
        • Functions
        • Arrays
      • section_4
        • Testing
        • Array Functions
        • JSON
        • Files
      • section_2
        • Looping Constructs
        • If statement
        • Match
        • Operators
      • section_1
        • Primitive Datentypen
        • Schlüsselwörter
        • Formatted Print
        • Strings
        • Kommentare
        • Variables
    • CONTRIBUTING_de
  • V dengan Contoh
    • examples
      • section1
        • Variabel
  • 通过例子学V语言
    • 例子
      • section_3
        • 函数
        • 方法
        • 数组
        • 结构体
      • section_1
        • 基本类型
        • 关键字
        • 变量
        • print系列函数
        • 字符
        • 注释
      • section_4
        • 文件
        • JSON操作
        • 调试
        • 数组函数
      • section_2
        • 运算符
        • 循环结构
        • If表达式
        • 匹配
  • コード例で学ぶV言語
    • examples
      • section_3
        • 関数
        • メソッド
        • 配列
        • 構造体
      • section_1
        • プリミティブ型
        • キーワード
        • 変数
        • 書式付き出力
        • 文字列
        • コメント
      • section_4
        • ファイル操作
        • JSON操作
        • テスト
        • 配列の関数
      • section_2
        • 演算子
        • ループ
        • If文
        • マッチ
  • Changelog
  • Contributing
  • Documentation Style Guide
Powered by GitBook
On this page
  • 基本运算符
  • 比较运算符
  • 布尔运算符
  • 按位运算符
  • 赋值运算符
  • 特殊运算符

Was this helpful?

  1. 通过例子学V语言
  2. 例子
  3. section_2

运算符

V支持以下运算符:

基本运算符

  • + (加法) 用于 int, float和string

  • - (减法) 用于 int和float类型

  • * (乘法) 用于 int和float类型

  • / (除法) 用于 int和float类型

  • % (取模) 用于 int类型

  • = (赋值) 用于改变值

  • := 用于初始化值

println(3 + 5)
println(2.0 + 5.0)
println('hello' + 'world')

println(9 - 10)
println(7.0 - 5.0)

println(3 * 5)
println(2.0 * 4)

println(23 / 3)
println(25.0 / 5.0)

println(27 % 5)
println(27 % 3)

输出

8
7.0
hello world

-1
2.0

15
8.0

7
5.0

2
0

注意:与其他语言不同,V不允许带浮点数的模。

比较运算符

  • >大于

  • <小于

  • =等于

  • >=大于或等于

  • <=小于或等于

  • !=不等于

布尔运算符

  • &amp;&amp;和

  • ||或

  • !非

按位运算符

  • <<左位移

  • >>右位移

  • &amp;按位和

  • |按位或

  • ^按位异或

赋值运算符

  • +=与foo=foo+var相同

  • -=与foo=foo-var相同

  • *=与foo=foo*var相同

  • /=与foo=foo/var相同

  • &amp;=与foo=foo&amp;var相同

  • |=与foo=foo'var相同

  • >=与foo=foo>>变量相同

  • <=与foo=foo<<var相同

特殊运算符

  • in for membership

  • none for optional

Previoussection_2Next循环结构

Last updated 5 years ago

Was this helpful?