All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to Use the Constant Generator iota in Golang

Working with Constants and iota in Go. The Constant Generator iota Here’s an example from the time package, which defines named constants of type Weekday for the days of the week, starting with zero for Sunday. Types of this kind are often called en...
pooriabt

How to Use bytes.Buffer in Golang

Golang bytes.Buffer Examples Examples of Golang bytes.Buffer The bytes package provides the Buffer type for efficient manipulation of byte slices. A Buffer starts out empty but grows as data of types like string, byte, and []byte are written to it. ...
ada

How to Add Two Numbers in Go

An example program using numbers. Integers And Floating Point Numbers Go has several different types to represent numbers. Generally we split numbers into two different kinds: integers and floating-point numbers. Make a main.go file containing the ...
pooriabt

How to Determine if an Object is Iterable in Python

In Python, there are 2 ways to determine if an object is iterable. Using Duck Typing Duck typing is a concept related to dynamic typing, where the type or the class of an object is less important than the methods it defines. When you use duck typing...
Unused

How to Count the Items in the Map in Go

In Golang, using the len function is the easiest way to count the items in the map structure. Using len Function The built-in function len take arguments of various types and return a result of type int. The implementation guarantees that the result...
Sambhav Khandelwal

How to Check If an Object Is of a Given Type in Python

In Python, there are 2 ways to check if an object is of a given type. Using isinstance Method The isinstance(object, classinfo) method returns True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtua...
Unused

How to Get the Maximum Value for an Int Type in Go

In Golang, there are 2 ways to get the maximum value for an int type. Using constant values Since integer types use two's complement arithmetic, you can infer the min/max constant values for int and uint. For example, package main import ( "...
Patcher56

How to Know If an Object has an Attribute in Python

In Python, there are 4 ways to know if an object has an attribute. Using hasattr Method The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. For example, #!/usr/...
ada

How to Access Command Line Parameters in Rust

In Rust, there are 2 ways to access command line parameters. Using std::env::args Function This function actually returns the arguments that this program was started with. See the following example: use std::env; fn main() { for arg in env::...
Patcher56

How to Remove Duplicates Strings from Slice in Go

In Golang, there are 2 ways to remove duplicates strings from slice.Using a Hash Map We have defined a function where we are passing the slice values and using the map function we are checking the duplicates and removing them. The ones that are curr...
pooriabt

How To Convert string to integer in Python

In Python, there are 2 ways to convert string to int. Using int Built-in Function Return an integer object constructed from a number or string x, or return 0 if no arguments are given. #!/usr/bin/python3 # -*- coding: utf8 -*- s = "100" # clas...
aweis

How To Install Go in Linux

In Golang, there are 2 ways to install Go in Linux.Download Packages Download packages for Windows 64-bit, macOS, Linux, and more. Go install Linux Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extr...
Unused

How to print a formatted string in Rust

Rust String Formatting and Printing Best Practices.Using println! Prints to the standard output, with a newline. Use the format! syntax to write data to the standard output. See std::fmt for more information. fn main() { let name = "Bob"; pri...
aweis

Rust error: cannot assign twice to immutable variable

In Rust, variables by default are immutable.Variables Immutable You can make them mutable by adding mut in front of the variable name. For example, fn main() { let x = 2; println!("value x: {}", x); x = 4; println!("value x: {}", x); } ...
Patcher56

How To Install Rust in Linux

In Rust, there are two ways to install rust in Linux.Running the following in your terminal If you’re running macOS, Linux, or another Unix-like OS. To download Rustup and install Rust, run the following in your terminal, then follow the on-screen i...
pooriabt