Skip to Content
Raku学习手册
book

Raku学习手册

by brian d foy
October 2020
Beginner to intermediate
499 pages
9h 13m
Chinese
China Electric Power Press Ltd.
Content preview from Raku学习手册
40
2
练习
2.7
修改你为上一个练习写的程序,让它接受一个十六进制数命令行参数。如果只
使用目前为止学到的知识,你的程序现在只能处理十六进制数。
2.4
数值操作
数值操作符可以将数转换为新的值。最简单的演示是直接输出结果。
+
是加法操作符:
put 2 + 2;
还可以把这个结果存储在一个变量中,然后输出这个变量。项赋值是一个操作,加
法也是一个操作。
+
先完成,因为它的优先级更高:
my $sum = 2 + 2;
put $sum;
另外还有减法
(-)
、乘法
(*)
、除法
(/)
和求幂
(**)
操作符。下一章会了解更多
有关内容。
输出一个数很容易。如果想输出一系列的数,可以写多行代码:
my $sum = 0;
put $sum + 1;
put $sum + 1 + 1;
put $sum + 1 + 1 + 1;
每次多加一个
1
。这会有大量重复。可以做一些改进,使得每种情况下
put
语句都是
一样的:
my $sum = 0;
$sum = $sum + 1;
put $sum;
$sum = $sum + 1;
put $sum;
$sum = $sum + 1;
put $sum;
猜数
41
$sum
变量出现在赋值的左边和右边。这是可以的,编译器不会搞混。它会用
$sum
当前值计算右边的结果。右边简化为一个值时,再把这个值赋给 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
程序员学数据结构

程序员学数据结构

Posts & Telecom Press, William Smith
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen

Publisher Resources

ISBN: 9787519848002